log4net(c#) 配置及使用

1. 首先从apache网站下载log4net, http://logging.apache.org/log4net/download_log4net.cgi 。我下的是最新版本 log4net-1.2.11-bin-newkey

2. 将 in et4.0 eleaselog4net.dll 复制到你的项目中 。

3. 将log4net.dll 添加引用到你的项目中。

4. 添加如下内容到 assemblyinfo.cs。

[assembly: log4net.Config.XmlConfigurator(ConfigFile = "config/log4net.config")]

configfile就是log4net.config的位置

5.引用

public  class LogHelper

{

private static ILog _log = LogManager.GetLogger(typeof (LogHelper));

public static void Log(string msg,params object[] p)
{
if(p.Length>0)
_log.Info(string.Format(msg,p));
else
_log.Info(msg);
}

}

在那个类中用log就LogManager.GetLogger(typeof (LogHelper));

就可以了。

原文地址:https://www.cnblogs.com/sheseido/p/3730583.html