Repository navigation
Expand file tree
/
Copy pathLoggingExtensions.cs
More file actions
45 lines (39 loc) · 1.64 KB
/
Copy pathLoggingExtensions.cs
File metadata and controls
45 lines (39 loc) · 1.64 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
42
43
44
45
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
namespace Microsoft.Extensions.Logging
{
internal static class LoggingExtensions
{
private static Action<ILogger, string, Exception> _tokenValidationFailed;
private static Action<ILogger, Exception> _tokenValidationSucceeded;
private static Action<ILogger, Exception> _errorProcessingMessage;
static LoggingExtensions()
{
_tokenValidationFailed = LoggerMessage.Define<string>(
eventId: 1,
logLevel: LogLevel.Information,
formatString: "Failed to validate the token {Token}.");
_tokenValidationSucceeded = LoggerMessage.Define(
eventId: 2,
logLevel: LogLevel.Information,
formatString: "Successfully validated the token.");
_errorProcessingMessage = LoggerMessage.Define(
eventId: 3,
logLevel: LogLevel.Error,
formatString: "Exception occurred while processing message.");
}
public static void TokenValidationFailed(this ILogger logger, string token, Exception ex)
{
_tokenValidationFailed(logger, token, ex);
}
public static void TokenValidationSucceeded(this ILogger logger)
{
_tokenValidationSucceeded(logger, null);
}
public static void ErrorProcessingMessage(this ILogger logger, Exception ex)
{
_errorProcessingMessage(logger, ex);
}
}
}