测试结果
输出日志内容:
2017-09-11 19:38:02,276 | log4 bigdata test: 0
2017-09-11 19:38:02,279 | log4 bigdata test: 1
... ...
... ...
2017-09-11 19:38:02,279 | log4 bigdata test: 199998
2017-09-11 19:38:02,279 | log4 bigdata test: 199999
Log4net耗时:
写入行数:200000, 毫秒数:7749
2.Nlog
配置
nlog.config
<?xml version="1.0" encoding="utf-8" ?>
<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
autoReload="true"
internalLogLevel="Warn"
internalLogFile="internal-nlog.txt">
<!-- define various log targets -->
<targets>
<!-- write logs to file -->
<target xsi:type="File" name="ownFile-web" fileName="logs/nlog-own-${shortdate}.log"
layout="${longdate} | ${message}"
archiveAboveSize="1048576"/>
</targets>
<rules>
<logger name="*" minlevel="Trace" writeTo="ownFile-web" />
</rules>
</nlog>
测试结果
输出日志内容:
2017-09-11 19:38:02,276 | nlog bigdata test: 0
2017-09-11 19:38:02,279 | nlog bigdata test: 1
......
......
2017-09-11 19:38:02,279 | nlog bigdata test: 199998
2017-09-11 19:38:02,279 | nlog bigdata test: 199999
Nlog耗时:
写入行数:200000, 毫秒数:104468
测试用例二:启用Buffer,连续插入20W行
1.Log4net
配置 log4net.config
...... <log4net> <appender name="RollingLogFileAppender" type="log4net.Appender.RollingFileAppender"> <bufferSize value="100" /> ......
耗时:Log4net写入行数:200000, 毫秒数:4672
2.Nlog
配置
nlog.config
......
<targets>
<!-- write logs to file -->
<default-wrapper xsi:type="BufferingWrapper" bufferSize="100"/>
<target xsi:type="File" name="ownFile-web" fileName="logs/nlog-own-${shortdate}.log"
layout="${longdate} | ${message}"
archiveAboveSize="1048576"/>
</targets>
......
Nlog耗时:写入行数:200000, 毫秒数:1605
总结
| 日志组件 | 版本 | 环境 | 用例 | (启用Buffer=100)毫秒数 | (不启用Buffer)毫秒数 |
|---|---|---|---|---|---|
| log4net | 2.0.8 | .netcore 2.0 | 20W行文件写入 | 4672 | 7749 |
| nlog | 5.0.0-beta10 | .netcore 2.0 | 20W行文件写入 | 1605 | 104468 |
代码和配置文件都在上边了,不知道不同配置的机器结果如何。








