Fauna v10 .NET/C# Driver 1.0.1
 
Loading...
Searching...
No Matches
Logger.cs
Go to the documentation of this file.
1using Microsoft.Extensions.Logging;
2
3namespace Fauna.Util;
4
9internal static class Logger
10{
11 private static ILogger? s_logger;
12
16 public static ILogger Instance
17 {
18 get
19 {
20 if (s_logger == null)
21 {
22 s_logger = InitializeDefaultLogger();
23 }
24
25 return s_logger;
26 }
27 }
28
33 public static void Initialize(ILogger logger)
34 {
35 s_logger = logger;
36 }
37
45 private static ILogger InitializeDefaultLogger()
46 {
47 var logLevel = Environment.GetEnvironmentVariable("FAUNA_DEBUG");
48 var minLogLevel = LogLevel.None;
49
50 if (!string.IsNullOrEmpty(logLevel) && int.TryParse(logLevel, out var level))
51 {
52 if (level < (int)LogLevel.Trace || level > (int)LogLevel.None)
53 {
54 throw new ArgumentException(
55 $"Invalid FAUNA_DEBUG value of {level}; must be between 0 and 6 inclusive. Set to 0 for highest verbosity, default is 6 (no logging).");
56 }
57
58 minLogLevel = (LogLevel)level;
59 }
60
61 using ILoggerFactory factory = LoggerFactory.Create(builder => builder
62 .AddConsole(options => options.LogToStandardErrorThreshold = LogLevel.Trace)
63 .AddSimpleConsole(options =>
64 {
65 options.IncludeScopes = true;
66 options.SingleLine = true;
67 options.TimestampFormat = "yyyy-MM-ddTHH:mm:ss.fffZ ";
68 options.UseUtcTimestamp = true;
69 })
70 .SetMinimumLevel(minLogLevel));
71
72 return factory.CreateLogger("fauna-dotnet");
73 }
74}
System.ArgumentException ArgumentException