Skip to content

Commit

Permalink
Update logging config with http extension filters
Browse files Browse the repository at this point in the history
  • Loading branch information
ionite34 committed Jul 25, 2023
1 parent 5d4a96a commit fa8ac43
Showing 1 changed file with 19 additions and 18 deletions.
37 changes: 19 additions & 18 deletions StabilityMatrix.Avalonia/App.axaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -483,31 +483,35 @@ private static void OnExit(object? sender, ControlledApplicationLifetimeExitEven

private static LoggingConfiguration ConfigureLogging()
{
var logConfig = new LoggingConfiguration();

// File target
logConfig.AddRule(NLog.LogLevel.Debug, NLog.LogLevel.Fatal,
new FileTarget("logfile")
LogManager.Setup().LoadConfiguration(builder => {
var debugTarget = builder.ForTarget("console").WriteTo(new DebuggerTarget
{
Layout = "${message}"
}).WithAsync();

var fileTarget = builder.ForTarget("logfile").WriteTo(new FileTarget
{
Layout = "${longdate}|${level:uppercase=true}|${logger}|${message:withexception=true}",
ArchiveOldFileOnStartup = true,
FileName = "${specialfolder:folder=ApplicationData}/StabilityMatrix/app.log",
ArchiveFileName = "${specialfolder:folder=ApplicationData}/StabilityMatrix/app.{#}.log",
ArchiveNumbering = ArchiveNumberingMode.Rolling,
MaxArchiveFiles = 2
});

// Debugger Target
logConfig.AddRule(NLog.LogLevel.Trace, NLog.LogLevel.Fatal,
new DebuggerTarget("debugger")
{
Layout = "${message}"
});
}).WithAsync();

// Filter some sources to be warn levels or above only
builder.ForLogger("System.*").WriteToNil(NLog.LogLevel.Warn);
builder.ForLogger("Microsoft.*").WriteToNil(NLog.LogLevel.Warn);
builder.ForLogger("Microsoft.Extensions.Http.*").WriteToNil(NLog.LogLevel.Warn);

builder.ForLogger().FilterMinLevel(NLog.LogLevel.Trace).WriteTo(debugTarget);
builder.ForLogger().FilterMinLevel(NLog.LogLevel.Debug).WriteTo(fileTarget);
});

// Sentry
if (SentrySdk.IsEnabled)
{
logConfig.AddSentry(o =>
LogManager.Configuration.AddSentry(o =>
{
o.InitializeSdk = false;
o.Layout = "${message}";
Expand All @@ -521,9 +525,6 @@ private static LoggingConfiguration ConfigureLogging()
});
}

LogManager.Configuration = logConfig;


return logConfig;
return LogManager.Configuration;
}
}

0 comments on commit fa8ac43

Please sign in to comment.