mrfangzheng

Hope and fear are useless. Be confident, and always be prepared for the worst.
  首页  :: 新随笔  :: 联系 :: 管理

最简单的Log4Net配置

Posted on 2008-06-08 00:06  mrfangzheng  阅读(419)  评论(1编辑  收藏  举报
  1. 添加log4net.dll的引用
  2. 在项目的Properties/AssemblyInfo.cs中添加:
    [assembly: log4net.Config.XmlConfigurator()]
  3. 在入口Assembly中至少调用一次LoggerManager.GetLogger()
  4. App.config例子
    Code
  5. 在代码中使用

    private static ILog Logger = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);

       
    if(logger.IsDebugEnabled)

       
    {

            
    Logger.DebugFormat("{0} - {1}", MethodBase.GetCurrentMethod(), "Init");

        }


       

Code snippet for log4net