Browse Source

log exceptions

tags/v0.1.3
Robin Thoni 8 years ago
parent
commit
cf004cd9d8
1 changed files with 7 additions and 2 deletions
  1. 7
    2
      Luticate2.Utils/Middlewares/LuExceptionMiddleware.cs

+ 7
- 2
Luticate2.Utils/Middlewares/LuExceptionMiddleware.cs View File

3
 using Luticate2.Utils.Controllers;
3
 using Luticate2.Utils.Controllers;
4
 using Luticate2.Utils.Dbo.Basic;
4
 using Luticate2.Utils.Dbo.Basic;
5
 using Microsoft.AspNetCore.Http;
5
 using Microsoft.AspNetCore.Http;
6
+using Microsoft.Extensions.Logging;
6
 using Newtonsoft.Json;
7
 using Newtonsoft.Json;
7
 
8
 
8
 namespace Luticate2.Utils.Middlewares
9
 namespace Luticate2.Utils.Middlewares
10
     public class LuExceptionMiddleware
11
     public class LuExceptionMiddleware
11
     {
12
     {
12
         private readonly RequestDelegate _next;
13
         private readonly RequestDelegate _next;
14
+        private readonly ILogger<LuExceptionMiddleware> _logger;
13
 
15
 
14
-        public LuExceptionMiddleware(RequestDelegate next)
16
+        public LuExceptionMiddleware(RequestDelegate next, ILogger<LuExceptionMiddleware> logger)
15
         {
17
         {
16
             _next = next;
18
             _next = next;
19
+            _logger = logger;
17
         }
20
         }
18
 
21
 
19
         public async Task Invoke(HttpContext context)
22
         public async Task Invoke(HttpContext context)
24
             }
27
             }
25
             catch (LuResultException e)
28
             catch (LuResultException e)
26
             {
29
             {
30
+                _logger.LogError(e.Result.PrivateDetails + "\n" + e.Result.PublicDetails + "\n" + e.StackTrace);
27
                 var response = context.Response;
31
                 var response = context.Response;
28
                 response.ContentType = "application/json";
32
                 response.ContentType = "application/json";
29
                 response.StatusCode = e.Result.GetHttpCode();
33
                 response.StatusCode = e.Result.GetHttpCode();
35
                     Version = LuUtilsExtensions.Options.Version
39
                     Version = LuUtilsExtensions.Options.Version
36
                 })).ConfigureAwait(false);
40
                 })).ConfigureAwait(false);
37
             }
41
             }
38
-            catch (Exception e)//TODO
42
+            catch (Exception e)
39
             {
43
             {
44
+                _logger.LogError(e.ToString());
40
                 var response = context.Response;
45
                 var response = context.Response;
41
                 response.ContentType = "application/json";
46
                 response.ContentType = "application/json";
42
                 response.StatusCode = 500;
47
                 response.StatusCode = 500;

Loading…
Cancel
Save