In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-03 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article mainly introduces. Net core2.0 log components Log4net, Nlog simple performance test example analysis, has a certain reference value, interested friends can refer to, I hope you can learn a lot after reading this article, the following let Xiaobian take you to understand.
Test environment
Development tools: Vsual Studio 2017 15.3
Framework version: .net core 2.0
Operating system: window10 Enterprise 1703
Hardware configuration: CPU I3-4170 3.7GHz, 8G memory, solid state disk
Log component
Log4net 2.0.8
Nlog 5.0.0-beta10
Test case
1. Do not enable Buffer, insert 200000 lines of strings into the file continuously, and the maximum 1MB for a single file.
two。 Enable Buffer to be 100, insert 200000 lines of strings into the file continuously, and the maximum 1MB for a single file.
Testing method
Xunit unit test.
Test code
Using System;using System.Diagnostics;using System.IO;using Xunit;using Xunit.Abstractions;namespace Demo.Logging.Tests {/ Log4net, Nlog log file write comparison / public class BigDataTest {private readonly ITestOutputHelper output; public BigDataTest (ITestOutputHelper outputHelper) {output = outputHelper } / [Fact] public void Log4netTest () {log4net.Repository.ILoggerRepository repository = log4net.LogManager.CreateRepository ("NETCoreRepository"); var fileInfo = new FileInfo ("config/log4net.config"); log4net.Config.XmlConfigurator.Configure (repository, fileInfo); log4net.Config.BasicConfigurator.Configure (repository) Log4net.ILog log = log4net.LogManager.GetLogger (repository.Name, "NETCorelog4net"); var total = 200000; var sw = new Stopwatch (); sw.Start (); for (int I = 0; I < total; iTunes +) {log.Info ("log4 bigdata test:" + I);} sw.Stop (); log.Info ($"total: {total}, Elapsed: {sw.ElapsedMilliseconds}") Output.WriteLine ($"Log4net Test total: {total}, Elapsed: {sw.ElapsedMilliseconds}"); / [Fact] public void NlogTest () {NLog.Logger log = NLog.LogManager.GetCurrentClassLogger (); var total = 200000; var sw = new Stopwatch (); sw.Start (); for (int I = 0) I < total; iTunes +) {log.Info ("nlog bigdata test:" + I);} sw.Stop (); log.Info ($"total: {total}, Elapsed: {sw.ElapsedMilliseconds}"); output.WriteLine ($"NLog Test total: {total}, Elapsed: {sw.ElapsedMilliseconds}");}
Test case 1: do not enable caching, insert 20W rows continuously
1.Log4net
Configuration
Log4net.config
Test result
Output log contents:
2017-09-11 1914 385 02276 | log4 bigdata test: 0
2017-09-11 19 38 14 02279 | log4 bigdata test: 1
......
......
2017-09-11 19 38 14 02279 | log4 bigdata test: 199998
2017-09-11 19 38 14 02279 | log4 bigdata test: 199999
Log4net time consuming:
Lines written: 200000, milliseconds: 7749
2.Nlog
Configuration
Nlog.config
Test result
Output log contents:
2017-09-11 1914 385 02276 | nlog bigdata test: 0
2017-09-11 19 38 14 02279 | nlog bigdata test: 1
.
.
2017-09-11 19 38 14 02279 | nlog bigdata test: 199998
2017-09-11 19 38 14 02279 | nlog bigdata test: 199999
Nlog time consuming:
Lines written: 200000, milliseconds: 104468
Test case 2: enable Buffer and insert 20W rows continuously
1.Log4net
Configure log4net.config
. .
Time elapsed: rows written by Log4net: 200000, milliseconds: 4672
2.Nlog
Configuration
Nlog.config
. .
Nlog time: lines written: 200000, milliseconds: 1605
Summary
Log component version environment use case (enable Buffer=100) milliseconds (not Buffer enabled) milliseconds log4net2.0.8.netcore 2.020W line file write 46727749nlog5.0.0-beta10.netcore 2.020W line file write 1605104468
The code and configuration files are all above, and I don't know how the machines with different configurations will turn out.
Will people prefer nlog or log4net again? The time consumption of log4net is stable regardless of whether buffer is enabled or not. The time difference between before and after enabling buffer for nlog is 65 times, and it takes more than 100 seconds for buffer not to be enabled, although it is only 1.605 seconds after enabling buffer.
Thank you for reading this article carefully. I hope the article "sample Analysis of simple performance testing of .net core2.0 Log Module Log4net and Nlog" shared by the editor will be helpful to you. At the same time, I also hope that you will support us and pay attention to the industry information channel. More related knowledge is waiting for you to learn!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.