1. 安装
-
Nuget包管理,在搜索框中输入Common.Logging.Log4Net,我安装的Common.Logging.Log4Net1213的包。
-
程序集中自动添加:Common.Logging.dll、Common.Logging.Core.dll、Common.Logging.log4net1213.dll、log4net.dll。如果是手动添加,需要特别注意Common.Logging.log4net1213.dll、log4net.dll的版本必须匹配。
2.工程内配置
- 写配置文件,加入到App.config文件.
<!--配置节声明区域-->
<configSections>
<!--Log4Net配置-->
<sectionGroup name="common">
<section name="logging" type="Common.Logging.ConfigurationSectionHandler, Common.Logging" />
</sectionGroup>
</configSections>
<common>
<!--配置节设置区域开始-->
<!--[DEBUG < INFO < WARN < ERROR < FATAL]-->
<logging>
<factoryAdapter type="Common.Logging.Log4Net.Log4NetLoggerFactoryAdapter, Common.Logging.Log4Net1215">
<!--