-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathLogFactory.cs
35 lines (30 loc) · 1.02 KB
/
LogFactory.cs
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
using Avalonia;
using Avalonia.Controls;
using Microsoft.Extensions.Logging;
using ZLogger;
using ZLogger.Providers;
public static class LogFactory
{
private static readonly ILoggerFactory _factory = LoggerFactory.Create(logging =>
{
logging.ClearProviders();
if (Design.IsDesignMode)
{
logging.SetMinimumLevel(LogLevel.Error);
return;
}
logging.SetMinimumLevel(LogLevel.Trace);
logging.AddZLoggerRollingFile(options =>
{
// File name determined by parameters to be rotated
options.FilePathSelector = (timestamp, sequenceNumber)
=> $"Logs/{timestamp.ToLocalTime():yyyy-MM-dd}_{sequenceNumber:000}.log";
// The period of time for which you want to rotate files at time intervals.
options.RollingInterval = RollingInterval.Day;
});
});
public static ILogger CreateLogger<T>()
{
return _factory.CreateLogger<T>();
}
}