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

Question: what changes are honored with reloadOnChange? #154

Closed
mdebeus opened this issue Nov 15, 2018 · 5 comments
Closed

Question: what changes are honored with reloadOnChange? #154

mdebeus opened this issue Nov 15, 2018 · 5 comments
Labels

Comments

@mdebeus
Copy link

mdebeus commented Nov 15, 2018

I've basically copied your sample, so I am using almost the exact same configuration you have specified in your appsettings.json (except I put the log files somewhere else). I tried changing the path to my log file - the one in Async-File from .\Logs\serilog-configuration-sample.txt to .\Logs\MyLogs\serilog-configuration-sample.txt but that change was not picked up, and I only have the one log file in .\Logs.

I also tried changing the outputTemplate, but that change was not picked up either.

I am using this in asp.net core.

@tsimbalar
Copy link
Member

Hi ,

If I remember properly, the only changes that can be honored are the ones related to MinimumLevel.

void ApplyMinimumLevel(IConfigurationSection directive, Action<LoggerMinimumLevelConfiguration, LoggingLevelSwitch> applyConfigAction)
{
var minimumLevel = ParseLogEventLevel(directive.Value);
var levelSwitch = new LoggingLevelSwitch(minimumLevel);
applyConfigAction(loggerConfiguration.MinimumLevel, levelSwitch);
ChangeToken.OnChange(
directive.GetReloadToken,
() =>
{
if (Enum.TryParse(directive.Value, out minimumLevel))
levelSwitch.MinimumLevel = minimumLevel;
else
SelfLog.WriteLine($"The value {directive.Value} is not a valid Serilog level.");
});
}
}

A logging pipeline is "immutable by design" once it has been created, so it can no longer be altered. The only parts of the logging pipeline that support some sort of dynamic updates are the level, the same way you would work with a LoggingLevelSwitch in your code.

I thinks we were mentioning some doubts about that part here as well : #99

@skomis-mm
Copy link
Contributor

Tracked until we have updated documentation.

@andyvig
Copy link

andyvig commented Dec 11, 2019

Is there an example of how to make config reloading work? I downloaded the sample and changes to the minimumLevel in the config file don't seem to take effect without restarting the app.

@skomis-mm
Copy link
Contributor

Hi, @andyvig , make sure you pass reloadOnChange: true to the config file you change at runtime (AddJsonFile(..)).

Changes to top-level MinimumLevel section LevelSwitches are respected for dynamic update

@skomis-mm
Copy link
Contributor

Documentation was updated

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

4 participants