熱點推薦:
您现在的位置: 電腦知識網 >> 編程 >> Java編程 >> Java核心技術 >> 正文

在.Net程序中使用log4net記錄日志

2022-06-13   來源: Java核心技術 

  logj是java開發人員所熟悉他提供了強大的日志記錄功能lognet是為Net記錄日志開發的使用示例如下(C#)
  nfig文件
  <?xml version= encoding=utf ?>
  <configuration>
  <appSettings>
  <add key=lognetconfigfile value=nfig/>
  </appSettings>
  </configuration>
  nfig文件
  <?xml version= encoding=utf ?>
  <configuration>
  <! This section contains the lognet configuration settings >
  <lognet>
  <! Define some output appenders >
  <appender name=RollingLogFileAppender type=lognetAppenderRollingFileAppender>
  <param name=File value=Log\\LQSSSSlogtxt />
  <param name=AppendToFile value=true />
  <param name=MaxSizeRollBackups value= />
  <param name=MaximumFileSize value=KB />
  <param name=RollingStyle value=Size />
  <param name=StaticLogFileName value=true />
  <layout type=lognetLayoutPatternLayout>
  <param name=Header value=[Header]\r\n />
  <param name=Footer value=[Footer]\r\n />
  <param name=ConversionPattern value=%d [%t] %p %c [%x] %m%n />
  </layout>
  </appender>
  <appender name=ConsoleAppender type=lognetAppenderConsoleAppender>
  <layout type=lognetLayoutPatternLayout>
  <param name=ConversionPattern value=%d [%t] %p %c [%x] <%X{auth}> %m%n />
  </layout>
  </appender>
  <! Setup the root category add the appenders and set the default level >
  <root>
  <level value=INFO />
  <appenderref ref=RollingLogFileAppender />
  </root>
  <root>
  <level value=DEBUG />
  <appenderref ref=ConsoleAppender />
  </root>
  </lognet>
  </configuration>
  代碼文件
  using lognet;
  using lognetConfig;
  class Program
  {
  private static ILog logger = LogManagerGetLogger(SystemReflectionMethodBaseGetCurrentMethod()DeclaringType);
  
  /// <summary>
  /// 應用程序的主入口點
  /// </summary>
  [STAThread]
  static void Main(string[] args)
  {
  try
  {
  DOMConfiguratorConfigure(
  new FileInfo(ConfigurationSettingsAppSettings[lognetconfigfile]));
  loggerInfo(Start application);
  ConsoleWriteline(請按 <enter> 鍵退出);
  SystemConsoleReadLine();
  }
  catch (Exception e)
  {
  loggerInfo (e);
  }
  }
  }

From:http://tw.wingwit.com/Article/program/Java/hx/201311/26351.html
  • 上一篇文章:

  • 下一篇文章:
  • 推薦文章
    Copyright © 2005-2022 電腦知識網 Computer Knowledge   All rights reserved.