是否有可能使用企業圖書館記錄器登錄到按日期分組的多個文件?例如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. 升級到企業圖書館6.0「EnterpriseLibraryContainer」給人的問題
- 4. 約實體框架與企業圖書館及其他幾個
- 5. 企業庫日誌記錄塊滾動平面文件不寫入文件
- 6. WPF,棱鏡,Unitybootstrapper和企業圖書館記錄設置拋出異常日誌寫進程
- 7. 企業庫記錄
- 8. 企業庫日誌記錄 - 多線程日誌到多個日誌文件
- 9. ESB Toolkit和企業圖書館碰撞IIS的Web.Config
- 10. 一起使用RijndaelManaged,企業圖書館和Autofac
- 11. 不能與企業圖書館「類型選擇」窗口4.1
- 12. Paypal Payflow專業圖書館
- 13. 寫入每個記錄到文件中BPEL文件適配器
- 14. 企業庫日誌記錄
- 15. 企業庫不記錄
- 16. 圖書館的文件生成器iphone
- 17. 使用MS企業庫將信息記錄到磁盤文件
- 18. 企業庫日誌記錄到平面文件跟蹤偵聽
- 19. 圖書館寫JavaScript代碼
- 20. 圖書館從C程序寫一個odf文件
- 21. 爲我的個人圖書館編寫圖書館搜索程序,在選擇多詞時遇到問題
- 22. 正確書寫圖書館類
- 23. 使用我的圖書館的AAR文件,該文件對其他圖書館
- 24. 摩根記錄器不寫入文件
- 25. 記錄器不寫入文件Log4J
- 26. 如何使用多個電子表格可更新,企圖利用圖書館
- 27. NModbus寫入文件記錄
- 28. 寫入文件有記錄
- 29. 圖書館對圖書館的引用
- 30. JumpList?進入圖書館
謝謝,但沒有他,P :( –