Closed zach-delong closed 3 years ago
For further information, here is the actual code setting up the logging in context. https://github.com/ZacheryPD/S3G/blob/feature/logging/StaticSiteGenerator/ServicesConfiguration.cs
Most likely this happens because default 'internal' FileLogger's MinLevel is LogLevel.Debug (which filters all 'Trace' level entries): https://github.com/nreco/logging/blob/master/src/NReco.Logging.File/FileLoggerProvider.cs
When you use "SetMinimumLevel" method this configures minimal logging level for the log entries filtering that is common for all logging providers, however each logging provider can have its own 'MinLevel'. To override default FileLoggerProvider.MinLevel use this code:
loggingBuilder
.SetMinimumLevel(LogLevel.Trace)
.AddConsole()
.Services.Add(ServiceDescriptor.Singleton<ILoggerProvider, FileLoggerProvider>(
(srvPrv) => {
return new FileLoggerProvider($"log.txt", append: true) { MinLevel = LogLevel.Trace };
}
));
To avoid that I guess it would be enough to change a default value for MinLevel from LogLevel.Debug to LogLevel.Trace.
Default MinLevel was changed from Debug to Trace + added FileLoggerOptions.MinLevel property (these changes are shipped in 1.1.2).
Okay! Thank you for your help!
One question, and I'm happy to open a PR if it would make my question more clear, would it be better to maintain backwards compatibility by adding a new optional parameter for minimum log level? Or perhaps to add a new extension method to support it? That way it maintains backwards compatibility but it doesn't require manually creating the logger.
@ZacheryPD I'm sure that LogLevel.Debug was used instead of LogLevel.Trace (which is real minimal possible level) by mistake. In any way, filtering by log level in the logger provider is rarely used, usually rules are configured for all logging providers in the "Logging" config section. Users that need exactly LogLevel.Debug (which was by default) for the FileLoggingProvider now can set this level explicitely in FileLoggerOptions (or in appsettings.json config section).
Makes perfect sense to me. Thank you for explaining!
I am fiddling around with trace logging for debugging some of my code and I haven't been able to write the trace level to file no matter what I do. I have this configuration:
and my file output looks like this:
but my console log looks like this:
which is obviously more detailed. Is this style of configuration simply unsupported?