dotnet-dynamic-jwt-bearer/PoweredSoft.DynamicJwtBearer/LoggingExtensions.cs

39 lines
1.5 KiB
C#
Raw Normal View History

2020-07-23 12:50:46 -04:00
using Microsoft.Extensions.Logging;
using System;
namespace PoweredSoft.DynamicJwtBearer
{
internal static class LoggingExtensions
{
private static Action<ILogger, Exception> _tokenValidationFailed;
private static Action<ILogger, Exception> _tokenValidationSucceeded;
private static Action<ILogger, Exception> _errorProcessingMessage;
static LoggingExtensions()
{
_tokenValidationFailed = LoggerMessage.Define(
eventId: new EventId(1, "TokenValidationFailed"),
logLevel: LogLevel.Information,
formatString: "Failed to validate the token.");
_tokenValidationSucceeded = LoggerMessage.Define(
eventId: new EventId(2, "TokenValidationSucceeded"),
logLevel: LogLevel.Information,
formatString: "Successfully validated the token.");
_errorProcessingMessage = LoggerMessage.Define(
eventId: new EventId(3, "ProcessingMessageFailed"),
logLevel: LogLevel.Error,
formatString: "Exception occurred while processing message.");
}
public static void TokenValidationFailed(this ILogger logger, Exception ex)
=> _tokenValidationFailed(logger, ex);
public static void TokenValidationSucceeded(this ILogger logger)
=> _tokenValidationSucceeded(logger, null);
public static void ErrorProcessingMessage(this ILogger logger, Exception ex)
=> _errorProcessingMessage(logger, ex);
}
}