-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Expand file tree
/
Copy pathLoggingHelpers.cs
More file actions
108 lines (95 loc) · 2.75 KB
/
LoggingHelpers.cs
File metadata and controls
108 lines (95 loc) · 2.75 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
101
102
103
104
105
106
107
108
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
*--------------------------------------------------------------------------------------------*/
using Microsoft.Extensions.Logging;
using System.Diagnostics;
namespace GitHub.Copilot;
internal static class LoggingHelpers
{
internal static void LogTiming(
ILogger logger,
LogLevel level,
Exception? exception,
string message,
long startTimestamp)
{
if (!logger.IsEnabled(level))
{
return;
}
LogTimingCore(logger, level, exception, message, Stopwatch.GetElapsedTime(startTimestamp));
}
internal static void LogTiming<T1>(
ILogger logger,
LogLevel level,
Exception? exception,
string message,
long startTimestamp,
T1 arg1)
{
if (!logger.IsEnabled(level))
{
return;
}
LogTimingCore(logger, level, exception, message, Stopwatch.GetElapsedTime(startTimestamp), arg1);
}
internal static void LogTiming<T1, T2>(
ILogger logger,
LogLevel level,
Exception? exception,
string message,
long startTimestamp,
T1 arg1,
T2 arg2)
{
if (!logger.IsEnabled(level))
{
return;
}
LogTimingCore(logger, level, exception, message, Stopwatch.GetElapsedTime(startTimestamp), arg1, arg2);
}
internal static void LogTiming<T1, T2, T3>(
ILogger logger,
LogLevel level,
Exception? exception,
string message,
long startTimestamp,
T1 arg1,
T2 arg2,
T3 arg3)
{
if (!logger.IsEnabled(level))
{
return;
}
LogTimingCore(logger, level, exception, message, Stopwatch.GetElapsedTime(startTimestamp), arg1, arg2, arg3);
}
internal static void LogTiming<T1, T2, T3, T4>(
ILogger logger,
LogLevel level,
Exception? exception,
string message,
long startTimestamp,
T1 arg1,
T2 arg2,
T3 arg3,
T4 arg4)
{
if (!logger.IsEnabled(level))
{
return;
}
LogTimingCore(logger, level, exception, message, Stopwatch.GetElapsedTime(startTimestamp), arg1, arg2, arg3, arg4);
}
private static void LogTimingCore(
ILogger logger,
LogLevel level,
Exception? exception,
string message,
params object?[] args)
{
#pragma warning disable CA2254 // Timing call sites pass static templates through this helper.
logger.Log(level, exception, message, args);
#pragma warning restore CA2254
}
}