Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

.SetMinimumLevel() has no effect #13

Closed
OszkarOlah opened this issue Jun 6, 2020 · 2 comments
Closed

.SetMinimumLevel() has no effect #13

OszkarOlah opened this issue Jun 6, 2020 · 2 comments
Labels

Comments

@OszkarOlah
Copy link

I use this implementation in a Core Console app without settings file. This is how I create a logger:

var lf = LoggerFactory.Create(builder =>
	{
		builder.SetMinimumLevel(LogLevel.Trace);
		builder.AddDebug();
		builder.AddConsole(c => c.DisableColors = false);
		builder.AddFile($"{logPath}\\SomeName_{DateTime.Now:yyyy-MM-dd_HH-mm-ss-ffff}.log")
			.SetMinimumLevel(LogLevel.Trace);
	});
_logger = lf.CreateLogger<Program>();

Is there a way to set the default log level to LogLevel.Trace programmatically?

@VitaliyMF
Copy link
Contributor

Take a look to how "AddFile" extension method is implemented here: https://github.com/nreco/logging/blob/master/src/NReco.Logging.File/FileLoggerExtensions.cs

Instead of "AddFile" you may use:

builder.Services.Add(ServiceDescriptor.Singleton<ILoggerProvider, FileLoggerProvider>( 
	(srvPrv) => {
		return new FileLoggerProvider($"{logPath}\\SomeName_{DateTime.Now:yyyy-MM-dd_HH-mm-ss-ffff}.log", true) {  MinLevel = LogLevel.Trace  };
	}
));

This approach is not very intuitive in fact, and it might be more convenient to add MinLevel option to FileLoggerOptions. Let me know if this is what you're looking for.

@OszkarOlah
Copy link
Author

Yes, that's what I wanted to achieve. Thanks for your quick response.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants