-
Notifications
You must be signed in to change notification settings - Fork 110
/
LoggerExtensions.cs
32 lines (26 loc) · 1.36 KB
/
LoggerExtensions.cs
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
using System;
using Microsoft.Extensions.Logging;
namespace Hellang.Middleware.ProblemDetails
{
internal static class LoggerExtensions
{
private static readonly Action<ILogger, Exception> _unhandledException =
LoggerMessage.Define(LogLevel.Error, new EventId(1, "UnhandledException"), "An unhandled exception has occurred while executing the request.");
private static readonly Action<ILogger, Exception> _responseStarted =
LoggerMessage.Define(LogLevel.Warning, new EventId(2, "ResponseStarted"), "The response has already started, the problem details middleware will not be executed.");
private static readonly Action<ILogger, Exception> _problemDetailsMiddlewareException =
LoggerMessage.Define(LogLevel.Error, new EventId(3, "Exception"), "An exception was thrown attempting to execute the problem details middleware.");
public static void UnhandledException(this ILogger logger, Exception exception)
{
_unhandledException(logger, exception);
}
public static void ResponseStarted(this ILogger logger)
{
_responseStarted(logger, null);
}
public static void ProblemDetailsMiddlewareException(this ILogger logger, Exception exception)
{
_problemDetailsMiddlewareException(logger, exception);
}
}
}