-
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathErrorLoggingMiggleware.cs
More file actions
41 lines (38 loc) · 1.47 KB
/
ErrorLoggingMiggleware.cs
File metadata and controls
41 lines (38 loc) · 1.47 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
using System.Diagnostics;
namespace RatingAPI
{
public class ErrorLoggingMiddleware
{
private readonly RequestDelegate _next;
private readonly ILogger<ErrorLoggingMiddleware> _logger;
private readonly Process process;
public ErrorLoggingMiddleware(RequestDelegate next, ILogger<ErrorLoggingMiddleware> logger)
{
_next = next;
_logger = logger;
process = Process.GetCurrentProcess();
}
public async Task Invoke(HttpContext context)
{
try
{
var guid = Guid.NewGuid();
float before = (float)(Process.GetCurrentProcess().WorkingSet64 / 1000l) / 1000000.0f;
if (context.Request.Path != "/servername")
{
_logger.LogWarning(null, $"STARTED {guid} {before} GB {context.Request.Path}{context.Request.QueryString}");
}
await _next(context);
if (context.Request.Path != "/servername")
{
_logger.LogWarning(null, $"FINISHED {guid} {before} {(float)(Process.GetCurrentProcess().WorkingSet64 / 1000l) / 1000000.0f} GB {context.Request.Path}{context.Request.QueryString}");
}
}
catch (Exception e)
{
_logger.LogWarning(null, "LOL500 " + context.Request.Path + context.Request.QueryString);
throw;
}
}
}
}