We know microsoft has provide the log method, but how to use this method.
loggin.config as below:
First:
Should be deploy the web.config file as below:
- <configuration>
- <configSections>
- <section name="loggingConfiguration" type="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.LoggingSettings, Microsoft.Practices.EnterpriseLibrary.Logging"/>
- <loggingConfiguration configSource="ConfigFiles/logging.config"/>
- <?xml version="1.0" encoding="utf-8"?>
- <!--Logging configurations-->
- <loggingConfiguration name="Logging Application Block" tracingEnabled="true" defaultCategory="Default" logWarningsWhenNoCategoriesMatch="false">
- <listeners>
- <add fileName="Logs/web.log"
- rollSizeKB="0"
- timeStampPattern="yyyy-MM-dd"
- rollFileExistsBehavior="Increment"
- rollInterval="Month"
- formatter="Text Formatter"
- header="----------------------------------------"
- footer="----------------------------------------"
- listenerDataType="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.RollingFlatFileTraceListenerData, Microsoft.Practices.EnterpriseLibrary.Logging"
- traceOutputOptions="None"
- type="Microsoft.Practices.EnterpriseLibrary.Logging.TraceListeners.RollingFlatFileTraceListener, Microsoft.Practices.EnterpriseLibrary.Logging"
- name="Rolling Flat File Server Trace Listener" />
- <add fileName="Logs/SessionManagement.log"
- rollSizeKB="0"
- timeStampPattern="yyyy-MM-dd"
- rollFileExistsBehavior="Increment"
- rollInterval="Month"
- formatter="Text Formatter"
- header="----------------------------------------"
- footer="----------------------------------------"
- listenerDataType="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.RollingFlatFileTraceListenerData, Microsoft.Practices.EnterpriseLibrary.Logging"
- traceOutputOptions="None"
- type="Microsoft.Practices.EnterpriseLibrary.Logging.TraceListeners.RollingFlatFileTraceListener, Microsoft.Practices.EnterpriseLibrary.Logging"
- name="Session Management Rolling Flat File Server Trace Listener" />
- </listeners>
- <formatters>
- <add template="Timestamp: {timestamp(local:)}
- Message: {message}
- Extended Properties: {dictionary({key} - {value} )}
- Machine: {machine}"
- type="Microsoft.Practices.EnterpriseLibrary.Logging.Formatters.TextFormatter, Microsoft.Practices.EnterpriseLibrary.Logging"
- name="Text Formatter" />
- </formatters>
- <categorySources>
- <add switchValue="All" name="Default">
- <listeners>
- <add name="Rolling Flat File Server Trace Listener" />
- </listeners>
- </add>
- <add switchValue="All" name="SessionManagement">
- <listeners>
- <add name="Session Management Rolling Flat File Server 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"/>
- </specialSources>
- </loggingConfiguration>
Second:
We can add three dll as below to the bin folder in your solution.
1.Microsoft.Practices.EnterpriseLibrary.Common.dll
2.Microsoft.Practices.EnterpriseLibrary.Logging.dll
3.Microsoft.Practices.ObjectBuilder.dll
Last:
Can use the log method write the log to the log file as below:
- protected void Page_Load(object sender, EventArgs e)
- {
- Microsoft.Practices.EnterpriseLibrary.Logging.Logger.Write("Message", "Default");
- }
Hopefully help you to code.