serilog-mssql / serilog-sinks-mssqlserver

A Serilog sink that writes events to Microsoft SQL Server and Azure SQL
Apache License 2.0
278 stars 148 forks source link

LoggingLevelSwitch support #454

Closed raV720 closed 1 year ago

raV720 commented 1 year ago

Does this sink support runtime changes of LogEventLevel? If not then it would be really helpful to implement such option.

ckadluba commented 1 year ago

Hi @raV720!

Thank you for writing us. The log level setting is not managed by this sink but can be controlled by Microsoft.Extension.Logging or by Serilog.Extension.Logging respectively. It should be able to update the log level property depending on the source of the setting (appsettings).

Further reading: https://devblogs.microsoft.com/dotnet/asp-net-core-logging/ https://learn.microsoft.com/en-us/dotnet/core/extensions/logging?tabs=command-line#change-log-levels-in-a-running-app

raV720 commented 1 year ago

So according to https://learn.microsoft.com/en-us/dotnet/core/extensions/logging?tabs=command-line#change-log-levels-in-a-running-app it is not possible to change log level at runtime unless modifying appsetting.json?

Isn't it just matter of adding levelSwitch parameter in line: https://github.com/serilog-mssql/serilog-sinks-mssqlserver/blob/216330e944efa85cf5ebe2c3c4a28814fc50d583/src/Serilog.Sinks.MSSqlServer/Configuration/Extensions/Microsoft.Extensions.Configuration/LoggerConfigurationMSSqlServerExtensions.cs#L131

ckadluba commented 1 year ago

The code you are referring to is only called once during initialization of the logger. It cannot be called again later during runtime of your app.

raV720 commented 1 year ago

Yes, but if I understand correctly: passed levelSwitch can be used later during runtime to change log level.

ckadluba commented 1 year ago

Ah, got ya! I will look into that.

ckadluba commented 1 year ago

We just released the preview version 6.2.0-dev-00041 to nuget.org which features a way to pass a LevelSwitch via the sink options object.

Please try it out and let us know if you find any problems.