Use Microsofe log method and deploy the web.config file

We know microsoft has provide the log method, but how to use this method.
First:
Should be deploy the web.config file as below:
  1. <configuration>
  2.     <configSections>
  3.         <section name="loggingConfiguration" type="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.LoggingSettings, Microsoft.Practices.EnterpriseLibrary.Logging"/>
  1.     <loggingConfiguration configSource="ConfigFiles/logging.config"/>
loggin.config as below:
  1. <?xml version="1.0" encoding="utf-8"?>
  2. <!--Logging configurations-->
  3. <loggingConfiguration name="Logging Application Block" tracingEnabled="true" defaultCategory="Default" logWarningsWhenNoCategoriesMatch="false">
  4.   <listeners>
  5.     <add fileName="Logs/web.log"
  6.          rollSizeKB="0"
  7.          timeStampPattern="yyyy-MM-dd"
  8.          rollFileExistsBehavior="Increment"
  9.          rollInterval="Month"
  10.          formatter="Text Formatter"
  11.          header="----------------------------------------"
  12.          footer="----------------------------------------"
  13.          listenerDataType="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.RollingFlatFileTraceListenerData, Microsoft.Practices.EnterpriseLibrary.Logging"
  14.          traceOutputOptions="None"
  15.          type="Microsoft.Practices.EnterpriseLibrary.Logging.TraceListeners.RollingFlatFileTraceListener, Microsoft.Practices.EnterpriseLibrary.Logging"
  16.          name="Rolling Flat File Server Trace Listener" />
  17.     <add fileName="Logs/SessionManagement.log"
  18.      rollSizeKB="0"
  19.      timeStampPattern="yyyy-MM-dd"
  20.      rollFileExistsBehavior="Increment"
  21.      rollInterval="Month"
  22.      formatter="Text Formatter"
  23.      header="----------------------------------------"
  24.      footer="----------------------------------------"
  25.      listenerDataType="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.RollingFlatFileTraceListenerData, Microsoft.Practices.EnterpriseLibrary.Logging"
  26.      traceOutputOptions="None"
  27.      type="Microsoft.Practices.EnterpriseLibrary.Logging.TraceListeners.RollingFlatFileTraceListener, Microsoft.Practices.EnterpriseLibrary.Logging"
  28.      name="Session Management Rolling Flat File Server Trace Listener" />
  29.   </listeners>
  30.   <formatters>
  31.     <add template="Timestamp: {timestamp(local:)}
  32. Message:  {message}
  33. Extended Properties: {dictionary({key} - {value} )}
  34. Machine:  {machine}"
  35.           type="Microsoft.Practices.EnterpriseLibrary.Logging.Formatters.TextFormatter, Microsoft.Practices.EnterpriseLibrary.Logging"
  36.           name="Text Formatter" />
  37.   </formatters>
  38.   <categorySources>
  39.     <add switchValue="All" name="Default">
  40.       <listeners>
  41.         <add name="Rolling Flat File Server Trace Listener" />
  42.       </listeners>
  43.     </add>
  44.     <add switchValue="All" name="SessionManagement">
  45.       <listeners>
  46.         <add name="Session Management Rolling Flat File Server Trace Listener" />
  47.       </listeners>
  48.     </add>
  49.   </categorySources> 
  50.   <specialSources>
  51.     <allEvents switchValue="All" name="All Events" />
  52.     <notProcessed switchValue="All" name="Unprocessed Category" />
  53.     <errors switchValue="All" name="Logging Errors & Warnings"/>
  54.   </specialSources>
  55. </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:
  1.         protected void Page_Load(object sender, EventArgs e)
  2.         {
  3.             Microsoft.Practices.EnterpriseLibrary.Logging.Logger.Write("Message""Default");
  4.         }

Hopefully help you to code.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值