110,538
社区成员
发帖
与我相关
我的任务
分享
<?xml version="1.0" encoding="utf-8"?>
<loggingConfiguration name="" tracingEnabled="true" defaultCategory="Info">
<listeners>
<add name="Rolling Flat File Trace Listener"
type="Microsoft.Practices.EnterpriseLibrary.Logging.TraceListeners.RollingFlatFileTraceListener, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
listenerDataType="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.RollingFlatFileTraceListenerData, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
fileName="log/日志.txt"
formatter="Text Formatter"
rollFileExistsBehavior="Increment"
footer=""
header=""
timeStampPattern="yyyy-MM-dd"
rollInterval="Day"
rollSizeKB="1000" />
</listeners>
<formatters>
<add type="Microsoft.Practices.EnterpriseLibrary.Logging.Formatters.TextFormatter, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
template="{timestamp} [{category}] - {message} "
name="Text Formatter" />
</formatters>
<logFilters>
<add type="Microsoft.Practices.EnterpriseLibrary.Logging.Filters.LogEnabledFilter, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
enabled="true" name="Logging Enabled Filter" />
<add type="Microsoft.Practices.EnterpriseLibrary.Logging.Filters.PriorityFilter, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
name="Priority Filter" />
<add type="Microsoft.Practices.EnterpriseLibrary.Logging.Filters.CategoryFilter, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
name="Category Filter" />
</logFilters>
<categorySources>
<add switchValue="All" name="Info">
<listeners>
<add name="Rolling Flat File Trace Listener" />
</listeners>
</add>
<add switchValue="All" name="Trace">
<listeners>
<add name="Rolling Flat File Trace Listener" />
</listeners>
</add>
</categorySources>
<specialSources>
<allEvents switchValue="All" name="All Events" />
<notProcessed switchValue="All" name="Unprocessed Category" />
<errors switchValue="All" name="Logging Errors & Warnings">
<listeners>
</listeners>
</errors>
</specialSources>
</loggingConfiguration>
LogWriter logWriter = null;
logWriter = EnterpriseLibraryContainer.Current.GetInstance<LogWriter>();
LogEntry ent = new LogEntry();
ent.Categories.Add("Info");//种类最好根据配置文件定义个枚举
while(true)
{
logWriter.Write("文件操作完成!" + name.ToString() + " " + DateTime.Now.ToString());
Thread.Sleep(100);
}
Version=6.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35
就是指上面这种文本去掉<add type="Microsoft.Practices.EnterpriseLibrary.Logging.Formatters.TextFormatter, Microsoft.Practices.EnterpriseLibrary.Logging"
template="Timestamp: {timestamp(local)}{newline}
Message: {message}{newline}
Category: {category}{newline}
Priority: {priority}{newline}
EventId: {eventid}{newline}
Severity: {severity}{newline}
Title:{title}{newline}
Extended Properties: {dictionary({key} - {value}{newline})}"
name="Text Formatter" />