开发环境:
VS,
MVC 4.0,
.Net Framework 4.0,
Log4net1.2.13.0,
Mysql.Data.dll,6.8.3.0
设置步骤:
1.在站点根目录下,创建一个log4net.config的XML文件。(文件名称可以任意,我们这里叫做log4net.config)
2.项目可视化下,Properties/AssemblyInfo.cs中添加:
[assembly: log4net.Config.XmlConfigurator(ConfigFile = "log4net.config", Watch = true)]
3.global.asax.cs文件中执行:
protected void Application_Start()
{
//独立的log4net.config
log4net.Config.XmlConfigurator.Configure(new FileInfo("log4net.config"));
AreaRegistration.RegisterAllAreas();
WebApiConfig.Register(GlobalConfiguration.Configuration);
FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
RouteConfig.RegisterRoutes(RouteTable.Routes);
BundleConfig.RegisterBundles(BundleTable.Bundles);
}
4.调用写日志方法:
ILog logger = LogManager.GetLogger(typeof(AlbumServcie));
logger.ErrorFormat("GetAlbumModel IsIISCache={0} throw Exception={1}", IsIISCache, ex.Message);
注意:
在log4net。config中,删除:
参考:
1./mahope/archive//04/14/375221.html
2./log4net/release/config-examples.html
3./zhoufoxcn/article/details/2220533
原文:/wangqiideal/p/4707792.html