【发布时间】:2014-11-11 17:03:11
【问题描述】:
我想记录到一组特定的文件/文件夹一段时间,然后切换并开始记录到另一组文件。为此,我使用 fluent API 来设置我想要的文件名(此处未显示)。但我无法在程序中途更改配置。它没有按我预期的方式工作。如果我第二次设置配置,是否有任何命令可以重新加载或清除我需要执行的配置?
如果我注释掉FirstConfig(); 和下一个Log 语句,那么SecondConfig() 工作正常。否则,似乎只有FirstConfig() 有效果。
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);
}
【问题讨论】:
标签: c# enterprise-library enterprise-library-5