-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathExtensions.cs
More file actions
64 lines (56 loc) · 1.85 KB
/
Extensions.cs
File metadata and controls
64 lines (56 loc) · 1.85 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
using System.Runtime.CompilerServices;
namespace ptr727.LanguageTags.Create;
internal static partial class LogExtensions
{
extension(Serilog.ILogger logger)
{
internal bool LogAndPropagate(
Exception exception,
[CallerMemberName] string function = "unknown"
)
{
logger.Error(exception, "{Function}", function);
return false;
}
internal bool LogAndHandle(
Exception exception,
[CallerMemberName] string function = "unknown"
)
{
logger.Error(exception, "{Function}", function);
return true;
}
internal Serilog.ILogger LogOverrideContext() => logger.ForContext<LogOverride>();
}
extension(Microsoft.Extensions.Logging.ILogger logger)
{
internal bool LogAndPropagate(
Exception exception,
[CallerMemberName] string function = "unknown"
)
{
logger.LogCatchException(function, exception);
return false;
}
internal bool LogAndHandle(
Exception exception,
[CallerMemberName] string function = "unknown"
)
{
logger.LogCatchException(function, exception);
return true;
}
}
[LoggerMessage(Message = "Exception in {Function}", Level = LogLevel.Error)]
internal static partial void LogCatchException(
this Microsoft.Extensions.Logging.ILogger logger,
string function,
Exception exception
);
[System.Diagnostics.CodeAnalysis.SuppressMessage(
"Design",
"CA1812:Avoid uninstantiated internal classes",
Justification = "Used as a type marker for Serilog context filtering"
)]
internal sealed class LogOverride;
}