是否有可能使用企业图书馆记录器登录到按日期分组的多个文件?例如Trace-08-22-2011.log,Trace-08-23-2011.log。写入到多个文件企业图书馆记录器
1
A
回答
1
<configSections>
<section name="loggingConfiguration" type="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.LoggingSettings, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" requirePermission="true" />
<section name="dataConfiguration" type="Microsoft.Practices.EnterpriseLibrary.Data.Configuration.DatabaseSettings, Microsoft.Practices.EnterpriseLibrary.Data, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" requirePermission="true" />
</configSections>
<!--Flat File Trace Listener-->
<loggingConfiguration name="Logging Application Block" tracingEnabled="true" defaultCategory="Default Category" logWarningsWhenNoCategoriesMatch="true">
<listeners>
<add source="Enterprise Library Logging" formatter="Text Formatter"
log="Application" machineName="" listenerDataType="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.FormattedEventLogTraceListenerData, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
traceOutputOptions="None" filter="All" type="Microsoft.Practices.EnterpriseLibrary.Logging.TraceListeners.FormattedEventLogTraceListener, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
name="Formatted EventLog TraceListener" />
<add fileName="D:\Works\GPIH\GPIAgent\Web\Log\Logger.log"
formatter="One Line Formatter" rollFileExistsBehavior="Increment"
rollInterval="Midnight" rollSizeKB="10000" timeStampPattern="yyyy-MM-dd"
listenerDataType="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.RollingFlatFileTraceListenerData, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
traceOutputOptions="None" filter="All" type="Microsoft.Practices.EnterpriseLibrary.Logging.TraceListeners.RollingFlatFileTraceListener, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
name="Rolling Flat File" />
</listeners>
<formatters>
<add template="Timestamp: {timestamp}{newline}
Message: {message}{newline}
Category: {category}{newline}
Machine: {localMachine}{newline}
App Domain: {localAppDomain}{newline}"
type="Microsoft.Practices.EnterpriseLibrary.Logging.Formatters.TextFormatter, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
name="Text Formatter" />
<add template="{timestamp(local)} Cat: {category} Pri: {priority} EId: {eventid} Sev: {severity} {message} Title:{title} Machine: {machine} Application Domain: {appDomain} Process Id: {processId} Process Name: {processName} Win32 Thread Id: {win32ThreadId} Thread Name: {threadName} Extended Properties: {dictionary({key} - {value}
)}"
type="Microsoft.Practices.EnterpriseLibrary.Logging.Formatters.TextFormatter, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
name="One Line Formatter" />
</formatters>
<logFilters>
<add name="LogEnabled Filter"
type="Microsoft.Practices.EnterpriseLibrary.Logging.Filters.LogEnabledFilter, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
enabled="true" />
</logFilters>
<categorySources>
<add switchValue="Warning" name="Default Category">
<listeners>
<add name="Formatted EventLog TraceListener" />
</listeners>
</add>
</categorySources>
<specialSources>
<allEvents switchValue="All" name="All Events">
<listeners>
<add name="Rolling Flat File" />
</listeners>
</allEvents>
<errors switchValue="All" name="Logging Errors & Warnings">
<listeners>
<add name="Formatted EventLog TraceListener" />
</listeners>
</errors>
</specialSources>
</loggingConfiguration>
1
是的,但不适用于随Enterprise-Library一起提供的TraceListener。你需要的是一个自定义TraceListener或至少TraceListenerData,它被间接用作一个跟踪监听器工厂(GetCreationExpression)。
您所描述的简单方法是从RollingFlatFileTraceListenerData继承并取代GetCreationExpression。它有这个.FileName保护字段可以设置为任何你想要的。例如,你可以解决您的自定义标记(时间戳)
/// <summary>
/// Returns a lambda expression that represents the creation of the trace listener described by this
/// configuration object.
/// </summary>
/// <returns>A lambda expression to create a trace listener.</returns>
protected override Expression<Func<TraceListener>> GetCreationExpression()
{
// Resolve tokens in FileName
string fileName = ResolveTokens(this.FileName);
return
() =>
new RollingFlatFileTraceListener(
fileName,
this.Header,
this.Footer,
Container.ResolvedIfNotNull<ILogFormatter>(this.Formatter),
this.RollSizeKB,
this.TimeStampPattern,
this.RollFileExistsBehavior,
this.RollInterval,
this.MaxArchivedFiles);
}
,并且配置:
<add name="All Activities 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="Sample.CustomFlatFileTraceListenerData, Sample"
fileName="%TEMP%\{timestamp}.log"
footer="" formatter="Detail Text Formatter" rollFileExistsBehavior="Overwrite"
rollInterval="Day" timeStampPattern="yyyy-MM-dd" maxArchivedFiles="10" />
相关问题
- 1. 企业图书馆记录器 - 电子邮件服务器设置
- 2. 面向方面编程和企业图书馆记录
- 3. 约实体框架与企业图书馆及其他几个
- 4. WPF,棱镜,Unitybootstrapper和企业图书馆记录设置抛出异常日志写进程
- 5. 企业库记录
- 6. 企业库日志记录 - 多线程日志到多个日志文件
- 7. Paypal Payflow专业图书馆
- 8. ESB Toolkit和企业图书馆碰撞IIS的Web.Config
- 9. 不能与企业图书馆“类型选择”窗口4.1
- 10. 一起使用RijndaelManaged,企业图书馆和Autofac
- 11. 使用企业库从多个进程记录到同一文件4.1
- 12. 写入每个记录到文件中BPEL文件适配器
- 13. 企业库不记录
- 14. 企业库日志记录
- 15. 使用MS企业库将信息记录到磁盘文件
- 16. 图书馆写JavaScript代码
- 17. 图书馆从C程序写一个odf文件
- 18. 正确书写图书馆类
- 19. 使用我的图书馆的AAR文件,该文件对其他图书馆
- 20. 记录器不写入文件Log4J
- 21. 如何使用多个电子表格可更新,企图利用图书馆
- 22. 加入预建图书馆
- 23. JumpList?进入图书馆
- 24. PhantomJS是图书馆重入?
- 25. 图书馆阅读许多文件文件格式?
- 26. 图书馆与多个模板定义
- 27. 一个图书馆多数据库
- 28. 多个消费者oAuth的图书馆?
- 29. 获取:使用企业图书馆“ExecuteXmlReader连接属性尚未初始化” 5.0
- 30. 企业图书馆5.0冒险:谁移动了我的奶酪(名字空间)
谢谢,但没有他,P :( –