I want to log to a particular set of files/folders for some time, and then switch and start logging to a different set of files. For this, I'm using the fluent API to set my filename as I want (not shown here). But I'm not able to change the configuration midway in a program. It is not working the way I expected it. Are there any commands to reload or clear the configuration that I need to do if I'm setting up the config a second time?
If I comment out FirstConfig();
and the next Log
statement, then the SecondConfig()
works fine. Else, only FirstConfig()
seems to have an effect.
static void Main(string[] args)
{
FirstConfig();
Logger.LogInfoMessage("Before processing"); //Some wrapper around EntLib logger methods
//Do some processing for some time
SecondConfig();
Logger.LogInfoMessage("After after processing");
}
private static void FirstConfig()
{
var textFormatter = new FormatterBuilder()
.TextFormatterNamed("First Text Formatter")
.UsingTemplate("{message}");
var builder = new ConfigurationSourceBuilder();
builder.ConfigureLogging()
.WithOptions.DoNotRevertImpersonation()
.LogToCategoryNamed("General").WithOptions.SetAsDefaultCategory()
.SendTo.FlatFile("First Listener")
.FormatWith(textFormatter).WithHeader("").WithFooter("")
.ToFile("Logs\\BeforeChange.log");
var configSource = new DictionaryConfigurationSource();
builder.UpdateConfigurationWithReplace(configSource);
EnterpriseLibraryContainer.Current = EnterpriseLibraryContainer.CreateDefaultContainer(configSource);
}
private static void SecondConfig()
{
var textFormatter = new FormatterBuilder()
.TextFormatterNamed("Second Text Formatter")
.UsingTemplate("{message}");
var builder = new ConfigurationSourceBuilder();
builder.ConfigureLogging()
.WithOptions.DoNotRevertImpersonation()
.LogToCategoryNamed("General").WithOptions.SetAsDefaultCategory()
.SendTo.FlatFile("Second Listener")
.FormatWith(textFormatter).WithHeader("").WithFooter("")
.ToFile("Logs\\AfterChange.log");
var configSource = new DictionaryConfigurationSource();
builder.UpdateConfigurationWithReplace(configSource);
EnterpriseLibraryContainer.Current = EnterpriseLibraryContainer.CreateDefaultContainer(configSource);
}