问题
I am using logging application block for EL 5.0. I defined listener like below.
<add name="FlatFile TraceListener" type="Microsoft.Practices.EnterpriseLibrary.
Logging.TraceListeners.FlatFileTraceListener,
Microsoft.Practices.EnterpriseLibrary.Logging"
listenerDataType="Microsoft.Practices.EnterpriseLibrary.
Logging.Configuration.FlatFileTraceListenerData,
Microsoft.Practices.EnterpriseLibrary.Logging"
fileName="C:\Temp\RssLog.log" header="--------------"
footer="----------------------" formatter="Brief Format Text"
traceOutputOptions="None" filter="All" />
How can generate log file daily?. like today=Rsslog10182011.log
tomorrow = Rsslog10182011.log
?
回答1:
If you use a rolling flat file trace listener that will give you a file for each day. This is from EL 4.1 but it is the same for EL5.
<add fileName=".\Logs\exception.log" footer="" formatter="Trace Formatter" header="" rollFileExistsBehavior="Overwrite" rollInterval="Midnight" rollSizeKB="0" timeStampPattern="yyyyMMdd" listenerDataType="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.RollingFlatFileTraceListenerData, Microsoft.Practices.EnterpriseLibrary.Logging, Version=4.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" traceOutputOptions="Callstack" filter="All" type="Microsoft.Practices.EnterpriseLibrary.Logging.TraceListeners.RollingFlatFileTraceListener, Microsoft.Practices.EnterpriseLibrary.Logging, Version=4.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" name="Exception TraceListener"/>
回答2:
Try using the Rolling Flat File Trace Listener instead. For example you could try this for starters:
<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="RssLog.log"
rollFileExistsBehavior="Increment"
rollInterval="Midnight" />
You can download the Enterprise Library 5.0 documentation for more details on configuring the Rolling Flat File Trace Listener.
来源:https://stackoverflow.com/questions/7812724/generate-logs-based-on-date-using-logging-application-block-for-el-5-0