【发布时间】:2011-12-15 17:04:43
【问题描述】:
有一些代码:
private const string FORMAT_TEXT =
"{timestamp}: [{category} ({win32ThreadId}-{threadName}) {severity}] |{title}|: {message}";
string path = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "trace.log");
var builder = new ConfigurationSourceBuilder();
builder.ConfigureLogging()
.WithOptions.DoNotRevertImpersonation()
.LogToCategoryNamed("Category1")
.SendTo.FlatFile("MyMessages1")
.FormatWith(new FormatterBuilder()
.TextFormatterNamed("Text Formatter 1").UsingTemplate(FORMAT_TEXT))
.ToFile(path)
.LogToCategoryNamed("Category2")
.SendTo.FlatFile("MyMessages2")
.FormatWith(new FormatterBuilder()
.TextFormatterNamed("Text Formatter 2").UsingTemplate(FORMAT_TEXT))
.ToFile(path);
var configSource = new DictionaryConfigurationSource();
builder.UpdateConfigurationWithReplace(configSource);
EnterpriseLibraryContainer.Current = EnterpriseLibraryContainer.CreateDefaultContainer(configSource);
for (int i = 0; i < 10; i++)
{
Logger.Write("Error message: " + i.ToString(), "Category1");
Logger.Write("Error message: " + i.ToString(), "Category2");
}
Console.ReadKey();
它会生成两个日志文件:trace.log 用于 Category1,65a25bb0-4c42-430d-b2b7-9bd2c8ea41e1trace.log 用于 Category2。我想记录到一个文件 trace.log。怎么了?
【问题讨论】:
标签: c# .net logging enterprise-library