Repository navigation
Expand file tree
/
Copy pathLoggerExtensions.cs
More file actions
100 lines (81 loc) · 3.63 KB
/
Copy pathLoggerExtensions.cs
File metadata and controls
100 lines (81 loc) · 3.63 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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
using System;
using Microsoft.Extensions.Logging;
namespace TestProcessWrapper.LongLived.Application;
internal static class LoggerExtensions
{
private static readonly Action<ILogger, Exception> OperationCancelledAction =
LoggerMessage.Define(
LogLevel.Information,
new EventId(1, nameof(OperationCancelled)),
"Operation has been canceled"
);
public static void OperationCancelled(this ILogger logger) =>
OperationCancelledAction(logger, null);
private static readonly Action<ILogger, Exception> WaitingForCancellationRequestAction =
LoggerMessage.Define(
LogLevel.Information,
new EventId(2, nameof(WaitingForCancellationRequest)),
"Waiting for cancellation request"
);
public static void WaitingForCancellationRequest(this ILogger logger) =>
WaitingForCancellationRequestAction(logger, null);
private static readonly Action<ILogger, Exception> StopRequestReceivedAction =
LoggerMessage.Define(
LogLevel.Information,
new EventId(3, nameof(StopRequestReceived)),
"STOP request received"
);
public static void StopRequestReceived(this ILogger logger) =>
StopRequestReceivedAction(logger, null);
private static readonly Action<ILogger, Exception> ShuttingDownAction = LoggerMessage.Define(
LogLevel.Information,
new EventId(4, nameof(ShuttingDown)),
"Shutting down ..."
);
public static void ShuttingDown(this ILogger logger) => ShuttingDownAction(logger, null);
private static readonly Action<ILogger, Exception> ShutDownCompleteAction =
LoggerMessage.Define(
LogLevel.Debug,
new EventId(5, nameof(ShutDownComplete)),
"Shutdown complete"
);
public static void ShutDownComplete(this ILogger logger) =>
ShutDownCompleteAction(logger, null);
private static readonly Action<ILogger, int, Exception> ProcessIdAction =
LoggerMessage.Define<int>(
LogLevel.Information,
new EventId(6, nameof(ProcessId)),
"Process ID {ProcessId}"
);
public static void ProcessId(this ILogger logger, int processId) =>
ProcessIdAction(logger, processId, null);
private static readonly Action<ILogger, string, Exception> ConfiguredEnvironmentVariableAction =
LoggerMessage.Define<string>(
LogLevel.Information,
new EventId(7, nameof(ConfiguredEnvironmentVariable)),
"Configured environment variable: \"{Value}\""
);
public static void ConfiguredEnvironmentVariable(this ILogger logger, string value) =>
ConfiguredEnvironmentVariableAction(logger, value, null);
private static readonly Action<ILogger, string, string, Exception> CommandLineArgumentAction =
LoggerMessage.Define<string, string>(
LogLevel.Information,
new EventId(8, nameof(CommandLineArgument)),
"Received the command line argument '{Argument}={Value}'"
);
public static void CommandLineArgument(this ILogger logger, string argument, string value) =>
CommandLineArgumentAction(logger, argument, value, null);
private static readonly Action<ILogger, Exception> BuildConfigurationAction =
LoggerMessage.Define(
LogLevel.Information,
new EventId(9, nameof(BuildConfiguration)),
"Build configuration: " +
#if DEBUG
"'Debug'"
#elif RELEASE
"'Release'"
#endif
);
public static void BuildConfiguration(this ILogger logger) =>
BuildConfigurationAction(logger, null);
}