mirror of
https://github.com/BililiveRecorder/BililiveRecorder.git
synced 2024-11-16 11:42:22 +08:00
parent
03ca7be644
commit
c12d2c1cb0
|
@ -384,25 +384,32 @@ namespace BililiveRecorder.Cli
|
||||||
.AddRecorder()
|
.AddRecorder()
|
||||||
.BuildServiceProvider();
|
.BuildServiceProvider();
|
||||||
|
|
||||||
private static Logger BuildLogger(LogEventLevel logLevel, LogEventLevel logFileLevel) => new LoggerConfiguration()
|
private static Logger BuildLogger(LogEventLevel logLevel, LogEventLevel logFileLevel)
|
||||||
.MinimumLevel.Verbose()
|
{
|
||||||
.Enrich.WithProcessId()
|
var logFilePath = Environment.GetEnvironmentVariable("BILILIVERECORDER_LOG_FILE_PATH");
|
||||||
.Enrich.WithThreadId()
|
if (string.IsNullOrWhiteSpace(logFilePath))
|
||||||
.Enrich.WithThreadName()
|
logFilePath = Path.Combine(AppContext.BaseDirectory, "logs", "bilirec.txt");
|
||||||
.Enrich.FromLogContext()
|
|
||||||
.Enrich.WithExceptionDetails()
|
return new LoggerConfiguration()
|
||||||
.Destructure.AsScalar<IPAddress>()
|
.MinimumLevel.Verbose()
|
||||||
.Destructure.ByTransforming<Flv.Xml.XmlFlvFile.XmlFlvFileMeta>(x => new
|
.Enrich.WithProcessId()
|
||||||
{
|
.Enrich.WithThreadId()
|
||||||
x.Version,
|
.Enrich.WithThreadName()
|
||||||
x.ExportTime,
|
.Enrich.FromLogContext()
|
||||||
x.FileSize,
|
.Enrich.WithExceptionDetails()
|
||||||
x.FileCreationTime,
|
.Destructure.AsScalar<IPAddress>()
|
||||||
x.FileModificationTime,
|
.Destructure.ByTransforming<Flv.Xml.XmlFlvFile.XmlFlvFileMeta>(x => new
|
||||||
})
|
{
|
||||||
.WriteTo.Console(restrictedToMinimumLevel: logLevel, outputTemplate: "[{Timestamp:HH:mm:ss} {Level:u3}] [{RoomId}] {Message:lj}{NewLine}{Exception}")
|
x.Version,
|
||||||
.WriteTo.File(new CompactJsonFormatter(), "./logs/bilirec.txt", restrictedToMinimumLevel: logFileLevel, shared: true, rollingInterval: RollingInterval.Day, rollOnFileSizeLimit: true)
|
x.ExportTime,
|
||||||
.CreateLogger();
|
x.FileSize,
|
||||||
|
x.FileCreationTime,
|
||||||
|
x.FileModificationTime,
|
||||||
|
})
|
||||||
|
.WriteTo.Console(restrictedToMinimumLevel: logLevel, outputTemplate: "[{Timestamp:HH:mm:ss} {Level:u3}] [{RoomId}] {Message:lj}{NewLine}{Exception}")
|
||||||
|
.WriteTo.File(new CompactJsonFormatter(), logFilePath, restrictedToMinimumLevel: logFileLevel, shared: true, rollingInterval: RollingInterval.Day, rollOnFileSizeLimit: true)
|
||||||
|
.CreateLogger();
|
||||||
|
}
|
||||||
|
|
||||||
public abstract class SharedArguments
|
public abstract class SharedArguments
|
||||||
{
|
{
|
||||||
|
|
|
@ -211,55 +211,63 @@ namespace BililiveRecorder.WPF
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Logger BuildLogger() => new LoggerConfiguration()
|
private static Logger BuildLogger()
|
||||||
.MinimumLevel.ControlledBy(levelSwitchGlobal)
|
{
|
||||||
.Enrich.WithProcessId()
|
var logFilePath = Environment.GetEnvironmentVariable("BILILIVERECORDER_LOG_FILE_PATH");
|
||||||
.Enrich.WithThreadId()
|
if (string.IsNullOrWhiteSpace(logFilePath))
|
||||||
.Enrich.WithThreadName()
|
logFilePath = Path.Combine(AppContext.BaseDirectory, "logs", "bilirec.txt");
|
||||||
.Enrich.FromLogContext()
|
|
||||||
.Enrich.WithExceptionDetails()
|
return new LoggerConfiguration()
|
||||||
.Destructure.AsScalar<IPAddress>()
|
.MinimumLevel.ControlledBy(levelSwitchGlobal)
|
||||||
.Destructure.ByTransforming<Flv.Xml.XmlFlvFile.XmlFlvFileMeta>(x => new
|
.Enrich.WithProcessId()
|
||||||
{
|
.Enrich.WithThreadId()
|
||||||
x.Version,
|
.Enrich.WithThreadName()
|
||||||
x.ExportTime,
|
.Enrich.FromLogContext()
|
||||||
x.FileSize,
|
.Enrich.WithExceptionDetails()
|
||||||
x.FileCreationTime,
|
.Destructure.AsScalar<IPAddress>()
|
||||||
x.FileModificationTime,
|
.Destructure.ByTransforming<Flv.Xml.XmlFlvFile.XmlFlvFileMeta>(x => new
|
||||||
})
|
{
|
||||||
.WriteTo.Console(levelSwitch: levelSwitchConsole)
|
x.Version,
|
||||||
|
x.ExportTime,
|
||||||
|
x.FileSize,
|
||||||
|
x.FileCreationTime,
|
||||||
|
x.FileModificationTime,
|
||||||
|
})
|
||||||
|
.WriteTo.Console(levelSwitch: levelSwitchConsole)
|
||||||
#if DEBUG
|
#if DEBUG
|
||||||
.WriteTo.Debug()
|
.WriteTo.Debug()
|
||||||
.WriteTo.Sink<WpfLogEventSink>(Serilog.Events.LogEventLevel.Debug)
|
.WriteTo.Sink<WpfLogEventSink>(Serilog.Events.LogEventLevel.Debug)
|
||||||
#else
|
#else
|
||||||
.WriteTo.Sink<WpfLogEventSink>(Serilog.Events.LogEventLevel.Information)
|
.WriteTo.Sink<WpfLogEventSink>(Serilog.Events.LogEventLevel.Information)
|
||||||
#endif
|
#endif
|
||||||
.WriteTo.File(new CompactJsonFormatter(), "./logs/bilirec.txt", shared: true, rollingInterval: RollingInterval.Day, rollOnFileSizeLimit: true)
|
.WriteTo.File(new CompactJsonFormatter(), logFilePath, shared: true, rollingInterval: RollingInterval.Day, rollOnFileSizeLimit: true)
|
||||||
.WriteTo.Sentry(o =>
|
.WriteTo.Sentry(o =>
|
||||||
{
|
{
|
||||||
o.Dsn = "https://38036b2031474b8ba0a728ac2a961cfa@o210546.ingest.sentry.io/5556540";
|
o.Dsn = "https://38036b2031474b8ba0a728ac2a961cfa@o210546.ingest.sentry.io/5556540";
|
||||||
o.SendDefaultPii = true;
|
o.SendDefaultPii = true;
|
||||||
o.IsGlobalModeEnabled = true;
|
o.IsGlobalModeEnabled = true;
|
||||||
o.DisableAppDomainUnhandledExceptionCapture();
|
o.DisableAppDomainUnhandledExceptionCapture();
|
||||||
o.DisableTaskUnobservedTaskExceptionCapture();
|
o.DisableTaskUnobservedTaskExceptionCapture();
|
||||||
o.AddExceptionFilterForType<HttpRequestException>();
|
o.AddExceptionFilterForType<HttpRequestException>();
|
||||||
o.AddExceptionFilterForType<OutOfMemoryException>();
|
o.AddExceptionFilterForType<OutOfMemoryException>();
|
||||||
o.AddExceptionFilterForType<JintException>();
|
o.AddExceptionFilterForType<JintException>();
|
||||||
o.AddExceptionFilterForType<ParserException>();
|
o.AddExceptionFilterForType<ParserException>();
|
||||||
o.AddEventProcessor(new SentryEventProcessor());
|
o.AddEventProcessor(new SentryEventProcessor());
|
||||||
|
|
||||||
o.TextFormatter = new MessageTemplateTextFormatter("[{RoomId}] {Message}{NewLine}{Exception}{@ExceptionDetail:j}");
|
o.TextFormatter = new MessageTemplateTextFormatter("[{RoomId}] {Message}{NewLine}{Exception}{@ExceptionDetail:j}");
|
||||||
|
|
||||||
o.MinimumBreadcrumbLevel = Serilog.Events.LogEventLevel.Debug;
|
o.MinimumBreadcrumbLevel = Serilog.Events.LogEventLevel.Debug;
|
||||||
o.MinimumEventLevel = Serilog.Events.LogEventLevel.Error;
|
o.MinimumEventLevel = Serilog.Events.LogEventLevel.Error;
|
||||||
|
|
||||||
#if DEBUG
|
#if DEBUG
|
||||||
o.Environment = "debug-build";
|
o.Environment = "debug-build";
|
||||||
#else
|
#else
|
||||||
o.Environment = "release-build";
|
o.Environment = "release-build";
|
||||||
#endif
|
#endif
|
||||||
})
|
})
|
||||||
.CreateLogger();
|
.CreateLogger();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
[DllImport("kernel32")]
|
[DllImport("kernel32")]
|
||||||
private static extern bool AttachConsole(int pid);
|
private static extern bool AttachConsole(int pid);
|
||||||
|
|
Loading…
Reference in New Issue
Block a user