本来系统中有个极其简陋写入文件方式记录日志的Loghelper,看到网上说的log4net很强大,
看看别人的说明,是特别强大的,就开始尝试,下面说明下填的坑.
log4net的引用及操作的说明可以参见C#使用log4net记录日志
https://www.cnblogs.com/kliine/p/10950859.html#commentform.
下面说下我填的坑吧.
上文什么都说明白了,就是一样没有说清楚, 里面的"项目"是哪个项目,
现在一般来说都是多层的,写log肯定是最底层的公共项目中(比如叫common),
第二步修改"AssemblyInfo.cs" 是指 common项目中的Assemblyinfo.cs文件
第三步增加的log4net.config文件也需放在也是放在 common项目下.最后发布时
需要确认下是否Copy到了web目录下去了
自己在抄作业的时候也出了问题,我换成.log结尾的文件,修改文件内容的时候,
最后面的%m没有写下来,整个需要输出内容都没有了.
当然,也发现作者的一个BUG,作者的输出格式中有个[%x]标记,下面说明文字中也没有,
输出文件中全都是null,这个应该是作者的失误了.
-----2020-10-29 更新2点-----
1)出现类似"20200603.log20200603" 这样的文件名
查资料是多线程同时写的时候会出错,需要进行对appender 节点里面增加如下设定
<!--最小锁定模型以允许多个进程可以写入同一个文件--> <param name="lockingModel" type="log4net.Appender.FileAppender+MinimalLock" />
2)UTF-8设定,解决中文乱码问题,需要进行对appender 节点里面增加如下设定
<param name="Encoding" value="utf-8" />