68 lines
1.8 KiB
C#
68 lines
1.8 KiB
C#
using Serilog;
|
|
using Serilog.Events;
|
|
using System;
|
|
|
|
namespace FluentTerminal.App.Services
|
|
{
|
|
public sealed class Logger
|
|
{
|
|
public enum LogLevel
|
|
{
|
|
Verbose = 0,
|
|
Debug = 1,
|
|
Information = 2,
|
|
Warning = 3,
|
|
Error = 4,
|
|
Fatal = 5
|
|
}
|
|
|
|
public class Configuration
|
|
{
|
|
public LogLevel LogLevel { get; set; } = LogLevel.Error;
|
|
}
|
|
|
|
public static Logger Instance { get; } = new Logger();
|
|
|
|
private Logger()
|
|
{
|
|
|
|
}
|
|
|
|
public void Initialize(string filePath, Configuration configuration)
|
|
{
|
|
Log.Logger = new LoggerConfiguration()
|
|
.WriteTo.Async(a => a.File(filePath, rollingInterval: RollingInterval.Day, retainedFileCountLimit: 7))
|
|
.MinimumLevel.Is((LogEventLevel)configuration.LogLevel)
|
|
.CreateLogger();
|
|
|
|
// Log file is not created during unhandled exception processing.
|
|
// Force log file creation with the highest severity initialization record.
|
|
Log.Fatal("Initialized");
|
|
}
|
|
|
|
public void Debug(string text, params object[] propertyValues)
|
|
{
|
|
Log.Debug(text, propertyValues, propertyValues);
|
|
}
|
|
|
|
public void Information(string text, params object[] propertyValues)
|
|
{
|
|
Log.Information(text, propertyValues);
|
|
}
|
|
|
|
public void Warning(string text, params object[] propertyValues)
|
|
{
|
|
Log.Warning(text, propertyValues);
|
|
}
|
|
|
|
public void Error(string text, params object[] propertyValues)
|
|
{
|
|
Log.Error(text, propertyValues);
|
|
}
|
|
|
|
public void Error(Exception exception, string text, params object[] propertyValues)
|
|
{
|
|
Log.Error(exception, text, propertyValues);
|
|
}
|
|
}
|
|
} |