잠시 동안 특정 파일/폴더 세트에 로그 한 다음 다른 파일 세트로 전환하고 로깅을 시작합니다. 이를 위해 유창한 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);
}