I m using Microsoft Enterprise Library 3.1 for Exception Handling in asp.net, the erors are stored in Event Viewer of the system . Instead of Event Viewer I need to store these errors in a log File using Enterprise Library. Suggest some methods to implement it. Thanks in advance.
A:
You need to read about Flat File Trace Listener/Rolling Flat File Trace Listener and Trace Listeners in general.
RichardOD
2009-10-01 12:14:35
If u give some examples like, it would be helpful i m confused implementing these listeners i tried Previously.plz
GayaMani
2009-10-01 12:23:54
Why don't you paste some of the code you tried, and describe the issue(s) you were encountering? I'm not going to paste something the documentation provides.
RichardOD
2009-10-01 13:26:46
+4
A:
In Entlib a Category is connected to a listener, then a listener determines where the log information is written. To log to a file use a Flat File Listener.
http://msdn.microsoft.com/en-us/library/cc309257.aspx
<listeners>
<add fileName="..\..\logfiles\BusinessActivity.log" rollSizeKB="10000" timeStampPattern="yyyy-MM-dd" rollFileExistsBehavior="Increment" rollInterval="None" formatter="Text Formatter" header="----------------------------------------" footer="----------------------------------------" listenerDataType="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.RollingFlatFileTraceListenerData, Microsoft.Practices.EnterpriseLibrary.Logging, Version=3.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" traceOutputOptions="None" type="Microsoft.Practices.EnterpriseLibrary.Logging.TraceListeners.RollingFlatFileTraceListener, Microsoft.Practices.EnterpriseLibrary.Logging, Version=3.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" name="Rolling Flat File BusinessActivity Listener" />
</listeners>
<formatters>
<add template="Timestamp: {timestamp(local)}
Message: {message}
Category: {category}
Priority: {priority}
EventId: {eventid}
Severity: {severity}
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=3.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" name="Text Formatter" />
</formatters>
<categorySources>
<add switchValue="All" name="BusinessActivityLog">
<listeners>
<add name="Rolling Flat File BusinessActivity Listener" />
</listeners>
</categorySources>
Shiraz Bhaiji
2009-10-01 12:19:05
+2
A:
Dear 2:30, You paste the following code inside configuration section at app.config or web.config file
<configSections>
<section name="loggingConfiguration" type="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.LoggingSettings, Microsoft.Practices.EnterpriseLibrary.Logging, Version=3.1.0.0, Culture=neutral, PublicKeyToken=null" />
<section name="dataConfiguration" type="Microsoft.Practices.EnterpriseLibrary.Data.Configuration.DatabaseSettings, Microsoft.Practices.EnterpriseLibrary.Data, Version=3.1.0.0, Culture=neutral, PublicKeyToken=null" />
</configSections>
<loggingConfiguration name="Logging Application Block" tracingEnabled="true" defaultCategory="Tracing" logWarningsWhenNoCategoriesMatch="true">
<listeners>
<add fileName="AppLog.log" rollSizeKB="1024" timeStampPattern="yyyy-MM-dd" rollFileExistsBehavior="Increment" rollInterval="None" formatter="Text Formatter" header="" footer="" listenerDataType="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.RollingFlatFileTraceListenerData, Microsoft.Practices.EnterpriseLibrary.Logging, Version=3.1.0.0, Culture=neutral, PublicKeyToken=null" traceOutputOptions="LogicalOperationStack" type="Microsoft.Practices.EnterpriseLibrary.Logging.TraceListeners.RollingFlatFileTraceListener, Microsoft.Practices.EnterpriseLibrary.Logging, Version=3.1.0.0, Culture=neutral, PublicKeyToken=null" name="AppLog" />
<add fileName="Exception.log" rollSizeKB="1024" timeStampPattern="MM-dd-yyyy" rollFileExistsBehavior="Increment" rollInterval="None" formatter="Text Formatter" header="" footer="" listenerDataType="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.RollingFlatFileTraceListenerData, Microsoft.Practices.EnterpriseLibrary.Logging, Version=3.1.0.0, Culture=neutral, PublicKeyToken=null" traceOutputOptions="Callstack" type="Microsoft.Practices.EnterpriseLibrary.Logging.TraceListeners.RollingFlatFileTraceListener, Microsoft.Practices.EnterpriseLibrary.Logging, Version=3.1.0.0, Culture=neutral, PublicKeyToken=null" name="Exception" />
<add fileName="trace.log" rollSizeKB="1024" timeStampPattern="yyyy-MM-dd" rollFileExistsBehavior="Increment" rollInterval="Month" formatter="Text Formatter" header="----------------------------------------" footer="----------------------------------------" listenerDataType="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.RollingFlatFileTraceListenerData, Microsoft.Practices.EnterpriseLibrary.Logging, Version=3.1.0.0, Culture=neutral, PublicKeyToken=null" traceOutputOptions="None" type="Microsoft.Practices.EnterpriseLibrary.Logging.TraceListeners.RollingFlatFileTraceListener, Microsoft.Practices.EnterpriseLibrary.Logging, Version=3.1.0.0, Culture=neutral, PublicKeyToken=null" name="Trace" />
</listeners>
<formatters>
<add template="{timestamp} : {message}" type="Microsoft.Practices.EnterpriseLibrary.Logging.Formatters.TextFormatter, Microsoft.Practices.EnterpriseLibrary.Logging, Version=3.1.0.0, Culture=neutral, PublicKeyToken=null" name="Text Formatter" />
</formatters>
<categorySources>
<add switchValue="All" name="AppLog">
<listeners>
<add name="AppLog" />
</listeners>
</add>
<add switchValue="Verbose" name="ExceptionHandling">
<listeners>
<add name="Exception" />
</listeners>
</add>
<add switchValue="Information" name="Tracing">
<listeners>
<add name="Trace" />
</listeners>
</add>
</categorySources>
<specialSources>
<allEvents switchValue="All" name="All Events" />
<notProcessed switchValue="All" name="Unprocessed Category" />
<errors switchValue="Off" name="Logging Errors & Warnings" />
</specialSources>
</loggingConfiguration>
Application log can be logged into applog.log file using following statement
Logger.Write("Application Started", "AppLog");
Application exception can be logged into Exception.log file using following statement
Logger.Write("Error: Invalid information you passed", "ExceptionHandling");
Note: You can find the Logger class in Microsoft.Practices.EnterpriseLibrary.Logging;
AppLog.log and Exception.log file will be created in bin folder automatically.
Sarathi1904
2009-10-05 09:10:35
Hi Sarathi, Thanks For u post, Its Working fine. I used Rolling Flat File Trace Listeners and it is working... Thanks again
GayaMani
2009-10-07 05:59:54