├── .gitattributes ├── .gitignore ├── LoggingPerformance.NLog ├── Foo.cs ├── LoggingPerformance.NLog.csproj └── Program.cs ├── LoggingPerformance.Serilog ├── Foo.cs ├── LoggingPerformance.Serilog.csproj └── Program.cs ├── LoggingPerformance.sln └── README.md /.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto 3 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | ## Ignore Visual Studio temporary files, build results, and 2 | ## files generated by popular Visual Studio add-ons. 3 | ## 4 | ## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore 5 | 6 | # User-specific files 7 | *.suo 8 | *.user 9 | *.userosscache 10 | *.sln.docstates 11 | 12 | # User-specific files (MonoDevelop/Xamarin Studio) 13 | *.userprefs 14 | 15 | # Build results 16 | [Dd]ebug/ 17 | [Dd]ebugPublic/ 18 | [Rr]elease/ 19 | [Rr]eleases/ 20 | x64/ 21 | x86/ 22 | bld/ 23 | [Bb]in/ 24 | [Oo]bj/ 25 | [Ll]og/ 26 | 27 | # Visual Studio 2015/2017 cache/options directory 28 | .vs/ 29 | # Uncomment if you have tasks that create the project's static files in wwwroot 30 | #wwwroot/ 31 | 32 | # Visual Studio 2017 auto generated files 33 | Generated\ Files/ 34 | 35 | # MSTest test Results 36 | [Tt]est[Rr]esult*/ 37 | [Bb]uild[Ll]og.* 38 | 39 | # NUNIT 40 | *.VisualState.xml 41 | TestResult.xml 42 | 43 | # Build Results of an ATL Project 44 | [Dd]ebugPS/ 45 | [Rr]eleasePS/ 46 | dlldata.c 47 | 48 | # Benchmark Results 49 | BenchmarkDotNet.Artifacts/ 50 | 51 | # .NET Core 52 | project.lock.json 53 | project.fragment.lock.json 54 | artifacts/ 55 | **/Properties/launchSettings.json 56 | 57 | # StyleCop 58 | StyleCopReport.xml 59 | 60 | # Files built by Visual Studio 61 | *_i.c 62 | *_p.c 63 | *_i.h 64 | *.ilk 65 | *.meta 66 | *.obj 67 | *.iobj 68 | *.pch 69 | *.pdb 70 | *.ipdb 71 | *.pgc 72 | *.pgd 73 | *.rsp 74 | *.sbr 75 | *.tlb 76 | *.tli 77 | *.tlh 78 | *.tmp 79 | *.tmp_proj 80 | *.log 81 | *.vspscc 82 | *.vssscc 83 | .builds 84 | *.pidb 85 | *.svclog 86 | *.scc 87 | 88 | # Chutzpah Test files 89 | _Chutzpah* 90 | 91 | # Visual C++ cache files 92 | ipch/ 93 | *.aps 94 | *.ncb 95 | *.opendb 96 | *.opensdf 97 | *.sdf 98 | *.cachefile 99 | *.VC.db 100 | *.VC.VC.opendb 101 | 102 | # Visual Studio profiler 103 | *.psess 104 | *.vsp 105 | *.vspx 106 | *.sap 107 | 108 | # Visual Studio Trace Files 109 | *.e2e 110 | 111 | # TFS 2012 Local Workspace 112 | $tf/ 113 | 114 | # Guidance Automation Toolkit 115 | *.gpState 116 | 117 | # ReSharper is a .NET coding add-in 118 | _ReSharper*/ 119 | *.[Rr]e[Ss]harper 120 | *.DotSettings.user 121 | 122 | # JustCode is a .NET coding add-in 123 | .JustCode 124 | 125 | # TeamCity is a build add-in 126 | _TeamCity* 127 | 128 | # DotCover is a Code Coverage Tool 129 | *.dotCover 130 | 131 | # AxoCover is a Code Coverage Tool 132 | .axoCover/* 133 | !.axoCover/settings.json 134 | 135 | # Visual Studio code coverage results 136 | *.coverage 137 | *.coveragexml 138 | 139 | # NCrunch 140 | _NCrunch_* 141 | .*crunch*.local.xml 142 | nCrunchTemp_* 143 | 144 | # MightyMoose 145 | *.mm.* 146 | AutoTest.Net/ 147 | 148 | # Web workbench (sass) 149 | .sass-cache/ 150 | 151 | # Installshield output folder 152 | [Ee]xpress/ 153 | 154 | # DocProject is a documentation generator add-in 155 | DocProject/buildhelp/ 156 | DocProject/Help/*.HxT 157 | DocProject/Help/*.HxC 158 | DocProject/Help/*.hhc 159 | DocProject/Help/*.hhk 160 | DocProject/Help/*.hhp 161 | DocProject/Help/Html2 162 | DocProject/Help/html 163 | 164 | # Click-Once directory 165 | publish/ 166 | 167 | # Publish Web Output 168 | *.[Pp]ublish.xml 169 | *.azurePubxml 170 | # Note: Comment the next line if you want to checkin your web deploy settings, 171 | # but database connection strings (with potential passwords) will be unencrypted 172 | *.pubxml 173 | *.publishproj 174 | 175 | # Microsoft Azure Web App publish settings. Comment the next line if you want to 176 | # checkin your Azure Web App publish settings, but sensitive information contained 177 | # in these scripts will be unencrypted 178 | PublishScripts/ 179 | 180 | # NuGet Packages 181 | *.nupkg 182 | # The packages folder can be ignored because of Package Restore 183 | **/[Pp]ackages/* 184 | # except build/, which is used as an MSBuild target. 185 | !**/[Pp]ackages/build/ 186 | # Uncomment if necessary however generally it will be regenerated when needed 187 | #!**/[Pp]ackages/repositories.config 188 | # NuGet v3's project.json files produces more ignorable files 189 | *.nuget.props 190 | *.nuget.targets 191 | 192 | # Microsoft Azure Build Output 193 | csx/ 194 | *.build.csdef 195 | 196 | # Microsoft Azure Emulator 197 | ecf/ 198 | rcf/ 199 | 200 | # Windows Store app package directories and files 201 | AppPackages/ 202 | BundleArtifacts/ 203 | Package.StoreAssociation.xml 204 | _pkginfo.txt 205 | *.appx 206 | 207 | # Visual Studio cache files 208 | # files ending in .cache can be ignored 209 | *.[Cc]ache 210 | # but keep track of directories ending in .cache 211 | !*.[Cc]ache/ 212 | 213 | # Others 214 | ClientBin/ 215 | ~$* 216 | *~ 217 | *.dbmdl 218 | *.dbproj.schemaview 219 | *.jfm 220 | *.pfx 221 | *.publishsettings 222 | orleans.codegen.cs 223 | 224 | # Including strong name files can present a security risk 225 | # (https://github.com/github/gitignore/pull/2483#issue-259490424) 226 | #*.snk 227 | 228 | # Since there are multiple workflows, uncomment next line to ignore bower_components 229 | # (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) 230 | #bower_components/ 231 | 232 | # RIA/Silverlight projects 233 | Generated_Code/ 234 | 235 | # Backup & report files from converting an old project file 236 | # to a newer Visual Studio version. Backup files are not needed, 237 | # because we have git ;-) 238 | _UpgradeReport_Files/ 239 | Backup*/ 240 | UpgradeLog*.XML 241 | UpgradeLog*.htm 242 | ServiceFabricBackup/ 243 | *.rptproj.bak 244 | 245 | # SQL Server files 246 | *.mdf 247 | *.ldf 248 | *.ndf 249 | 250 | # Business Intelligence projects 251 | *.rdl.data 252 | *.bim.layout 253 | *.bim_*.settings 254 | *.rptproj.rsuser 255 | 256 | # Microsoft Fakes 257 | FakesAssemblies/ 258 | 259 | # GhostDoc plugin setting file 260 | *.GhostDoc.xml 261 | 262 | # Node.js Tools for Visual Studio 263 | .ntvs_analysis.dat 264 | node_modules/ 265 | 266 | # Visual Studio 6 build log 267 | *.plg 268 | 269 | # Visual Studio 6 workspace options file 270 | *.opt 271 | 272 | # Visual Studio 6 auto-generated workspace file (contains which files were open etc.) 273 | *.vbw 274 | 275 | # Visual Studio LightSwitch build output 276 | **/*.HTMLClient/GeneratedArtifacts 277 | **/*.DesktopClient/GeneratedArtifacts 278 | **/*.DesktopClient/ModelManifest.xml 279 | **/*.Server/GeneratedArtifacts 280 | **/*.Server/ModelManifest.xml 281 | _Pvt_Extensions 282 | 283 | # Paket dependency manager 284 | .paket/paket.exe 285 | paket-files/ 286 | 287 | # FAKE - F# Make 288 | .fake/ 289 | 290 | # JetBrains Rider 291 | .idea/ 292 | *.sln.iml 293 | 294 | # CodeRush 295 | .cr/ 296 | 297 | # Python Tools for Visual Studio (PTVS) 298 | __pycache__/ 299 | *.pyc 300 | 301 | # Cake - Uncomment if you are using it 302 | # tools/** 303 | # !tools/packages.config 304 | 305 | # Tabs Studio 306 | *.tss 307 | 308 | # Telerik's JustMock configuration file 309 | *.jmconfig 310 | 311 | # BizTalk build output 312 | *.btp.cs 313 | *.btm.cs 314 | *.odx.cs 315 | *.xsd.cs 316 | 317 | # OpenCover UI analysis results 318 | OpenCover/ 319 | 320 | # Azure Stream Analytics local run output 321 | ASALocalRun/ 322 | 323 | # MSBuild Binary and Structured Log 324 | *.binlog 325 | 326 | # NVidia Nsight GPU debugger configuration file 327 | *.nvuser 328 | 329 | # MFractors (Xamarin productivity tool) working folder 330 | .mfractor/ 331 | -------------------------------------------------------------------------------- /LoggingPerformance.NLog/Foo.cs: -------------------------------------------------------------------------------- 1 | using LoggingPerformance.NLog.Logging; 2 | 3 | namespace LoggingPerformance.NLog 4 | { 5 | public static class Foo 6 | { 7 | private static readonly ILog Logger = LogProvider.GetCurrentClassLogger(); 8 | 9 | public static void Bar(int id, int totalCount) 10 | { 11 | Logger.Info("Log message {0} / {1}", id + 1, totalCount); 12 | } 13 | } 14 | } -------------------------------------------------------------------------------- /LoggingPerformance.NLog/LoggingPerformance.NLog.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | Exe 5 | netcoreapp2.0 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /LoggingPerformance.NLog/Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Diagnostics; 4 | using System.Linq; 5 | using System.Threading.Tasks; 6 | using LoggingPerformance.NLog.Logging; 7 | using LoggingPerformance.NLog.Logging.LogProviders; 8 | using NLog; 9 | using NLog.Config; 10 | using NLog.Targets; 11 | using NLog.Targets.Wrappers; 12 | using LogLevel = NLog.LogLevel; 13 | 14 | namespace LoggingPerformance.NLog 15 | { 16 | internal class Program 17 | { 18 | private static int _countPerThread = 5000000; 19 | private static int _producersCount = 1; 20 | private static int _totalCount; 21 | 22 | private static void Main(string[] args) 23 | { 24 | var config = new LoggingConfiguration(); 25 | 26 | var fileTarget = new FileTarget 27 | { 28 | Name = "FileTarget", 29 | FileName = "Log.txt", 30 | KeepFileOpen = true, 31 | ConcurrentWrites = false, 32 | AutoFlush = false 33 | }; 34 | 35 | var asyncFileTarget = new AsyncTargetWrapper(fileTarget) 36 | { 37 | TimeToSleepBetweenBatches = 0, 38 | OverflowAction = AsyncTargetWrapperOverflowAction.Block, 39 | BatchSize = 500 40 | }; 41 | 42 | config.AddTarget("file", asyncFileTarget); 43 | config.AddRuleForAllLevels(asyncFileTarget); 44 | LogManager.Configuration = config; 45 | LogManager.ReconfigExistingLoggers(); 46 | LogProvider.SetCurrentLogProvider(new NLogLogProvider()); 47 | 48 | //var config = new LoggingConfiguration(); 49 | //var consoleTarget = new ColoredConsoleTarget(); 50 | //config.AddTarget("console", consoleTarget); 51 | //config.LoggingRules.Add(new LoggingRule("*", LogLevel.Debug, consoleTarget)); 52 | //LogManager.Configuration = config; 53 | 54 | //var config = new LoggingConfiguration(); 55 | //var fileTarget = new FileTarget { FileName = "Log.Txt" }; 56 | //config.AddTarget("file", fileTarget); 57 | //config.LoggingRules.Add(new LoggingRule("*", LogLevel.Info, fileTarget)); 58 | //LogManager.Configuration = config; 59 | 60 | if (args.Length >= 1 && !int.TryParse(args[0], out _countPerThread) || _countPerThread < 1) 61 | { 62 | Console.WriteLine("Usage: LoggingPerformance.exe [CountPerThread] [ProducersCount] [ConsumersCount]"); 63 | throw new ArgumentException( 64 | "Invalid first argument! Provide items count per thread as a first application argument."); 65 | } 66 | 67 | if (args.Length >= 2 && !int.TryParse(args[1], out _producersCount) || _producersCount < 1) 68 | { 69 | Console.WriteLine("Usage: LoggingPerformance.exe [CountPerThread] [ProducersCount] [ConsumersCount]"); 70 | throw new ArgumentException( 71 | "Invalid second argument! Provide producers count as a second application argument."); 72 | } 73 | 74 | Console.WriteLine("NLog"); 75 | Console.WriteLine("Stopwatch.IsHighResolution = {0}", Stopwatch.IsHighResolution); 76 | 77 | _countPerThread = _countPerThread / _producersCount; 78 | _totalCount = _countPerThread * _producersCount; 79 | 80 | try 81 | { 82 | var results = new double[_totalCount]; 83 | for (var i = 0; i < _totalCount; i++) 84 | results[i] = 0; 85 | 86 | // Start the stopwatch timer. 87 | var stopWatch = Stopwatch.StartNew(); 88 | 89 | // Create and start producer tasks. 90 | var producers = new Task[_producersCount]; 91 | for (var producerIndex = 0; producerIndex < _producersCount; producerIndex++) 92 | producers[producerIndex] = Task.Factory.StartNew(state => 93 | { 94 | var index = (int)state; 95 | for (var i = 0; i < _countPerThread; i++) 96 | { 97 | var id = index * _countPerThread + i; 98 | results[id] = stopWatch.ElapsedTicks; 99 | 100 | Foo.Bar(id, _totalCount); 101 | 102 | results[id] = stopWatch.ElapsedTicks - results[id]; 103 | } 104 | }, producerIndex, TaskCreationOptions.LongRunning); 105 | 106 | // Wait for producing complete. 107 | Task.WaitAll(producers); 108 | stopWatch.Stop(); 109 | 110 | Console.WriteLine(); 111 | 112 | // Adjust result table. 113 | var frequency = Stopwatch.Frequency / (1000.0 * 1000.0); 114 | for (var i = 0; i < _totalCount; i++) 115 | results[i] /= frequency; 116 | Array.Sort(results); 117 | 118 | // Show report message. 119 | var throughput = _totalCount / ((double)stopWatch.ElapsedTicks / Stopwatch.Frequency); 120 | Console.WriteLine("Generated {0} values in {1}ms (throughput = {2:F3} ops per second)", _totalCount, 121 | stopWatch.ElapsedMilliseconds, throughput); 122 | 123 | // Show latency histogram. 124 | ShowHistogram(results, 10); 125 | } 126 | catch (Exception ex) 127 | { 128 | Console.WriteLine(ex.Message); 129 | } 130 | finally 131 | { 132 | // Wait for user stop action. 133 | Console.WriteLine("Press any key to stop..."); 134 | Console.ReadKey(); 135 | } 136 | } 137 | 138 | #region Utility methods 139 | 140 | private static void ShowHistogram(IList values, int count, double? maxValue = null) 141 | { 142 | // Calculate mean value. 143 | var mean = values.Aggregate((s, v) => s + v) / values.Count; 144 | Console.WriteLine("Mean latency = {0:F3}mcs", mean); 145 | 146 | // Calculate bounds values. 147 | var bound99 = (int)(values.Count * 99.0 / 100.0); 148 | Console.WriteLine("99% observations less than = {0:F3}mcs", values[bound99]); 149 | var bound9999 = (int)(values.Count * 99.99 / 100.0); 150 | Console.WriteLine("99.99% observations less than = {0:F3}mcs", values[bound9999]); 151 | 152 | var min = values[0]; 153 | var max = maxValue ?? values[bound99]; 154 | var step = (max - min) / count; 155 | 156 | for (var i = 0; i < count; i++) 157 | { 158 | var lower = min + i * step; 159 | var upper = min + (i + 1) * step; 160 | Console.WriteLine("{0}) {1:F3} - {2:F4} = {3}", i, lower, upper, 161 | values.Count(v => v >= lower && v <= upper)); 162 | } 163 | } 164 | 165 | #endregion 166 | } 167 | } -------------------------------------------------------------------------------- /LoggingPerformance.Serilog/Foo.cs: -------------------------------------------------------------------------------- 1 | using LoggingPerformance.Serilog.Logging; 2 | 3 | namespace LoggingPerformance.Serilog 4 | { 5 | public static class Foo 6 | { 7 | private static readonly ILog Logger = LogProvider.GetCurrentClassLogger(); 8 | 9 | public static void Bar(int id, int totalCount) 10 | { 11 | Logger.Info("Log message {0} / {1}", id + 1, totalCount); 12 | } 13 | } 14 | } -------------------------------------------------------------------------------- /LoggingPerformance.Serilog/LoggingPerformance.Serilog.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Exe 5 | netcoreapp2.0 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /LoggingPerformance.Serilog/Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Diagnostics; 4 | using System.Linq; 5 | using System.Threading.Tasks; 6 | using Serilog; 7 | 8 | namespace LoggingPerformance.Serilog 9 | { 10 | internal class Program 11 | { 12 | private static int _countPerThread = 5000000; 13 | private static int _producersCount = 1; 14 | private static int _totalCount; 15 | 16 | private static void Main(string[] args) 17 | { 18 | var log = new LoggerConfiguration() 19 | .WriteTo.File("Log.txt", buffered: true, flushToDiskInterval: TimeSpan.FromMilliseconds(1000)) 20 | .CreateLogger(); 21 | 22 | Log.Logger = log; 23 | 24 | if (args.Length >= 1 && !int.TryParse(args[0], out _countPerThread) || _countPerThread < 1) 25 | { 26 | Console.WriteLine("Usage: LoggingPerformance.exe [CountPerThread] [ProducersCount] [ConsumersCount]"); 27 | throw new ArgumentException( 28 | "Invalid first argument! Provide items count per thread as a first application argument."); 29 | } 30 | 31 | if (args.Length >= 2 && !int.TryParse(args[1], out _producersCount) || _producersCount < 1) 32 | { 33 | Console.WriteLine("Usage: LoggingPerformance.exe [CountPerThread] [ProducersCount] [ConsumersCount]"); 34 | throw new ArgumentException( 35 | "Invalid second argument! Provide producers count as a second application argument."); 36 | } 37 | 38 | Console.WriteLine("Serilog"); 39 | Console.WriteLine("Stopwatch.IsHighResolution = {0}", Stopwatch.IsHighResolution); 40 | 41 | _countPerThread = _countPerThread / _producersCount; 42 | _totalCount = _countPerThread * _producersCount; 43 | 44 | try 45 | { 46 | var results = new double[_totalCount]; 47 | for (var i = 0; i < _totalCount; i++) 48 | results[i] = 0; 49 | 50 | // Start the stopwatch timer. 51 | var stopWatch = Stopwatch.StartNew(); 52 | 53 | // Create and start producer tasks. 54 | var producers = new Task[_producersCount]; 55 | for (var producerIndex = 0; producerIndex < _producersCount; producerIndex++) 56 | producers[producerIndex] = Task.Factory.StartNew(state => 57 | { 58 | var index = (int) state; 59 | for (var i = 0; i < _countPerThread; i++) 60 | { 61 | var id = index * _countPerThread + i; 62 | results[id] = stopWatch.ElapsedTicks; 63 | 64 | // Different loggers will be used here for testing... 65 | //Logger.InfoFormat("Log message {0} / {1}", id + 1, _totalCount); 66 | 67 | Foo.Bar(id, _totalCount); 68 | 69 | results[id] = stopWatch.ElapsedTicks - results[id]; 70 | } 71 | }, producerIndex, TaskCreationOptions.LongRunning); 72 | 73 | // Wait for producing complete. 74 | Task.WaitAll(producers); 75 | stopWatch.Stop(); 76 | 77 | Console.WriteLine(); 78 | 79 | // Adjust result table. 80 | var frequency = Stopwatch.Frequency / (1000.0 * 1000.0); 81 | for (var i = 0; i < _totalCount; i++) 82 | results[i] /= frequency; 83 | Array.Sort(results); 84 | 85 | // Show report message. 86 | var throughput = _totalCount / ((double) stopWatch.ElapsedTicks / Stopwatch.Frequency); 87 | Console.WriteLine("Generated {0} values in {1}ms (throughput = {2:F3} ops per second)", _totalCount, 88 | stopWatch.ElapsedMilliseconds, throughput); 89 | 90 | // Show latency histogram. 91 | ShowHistogram(results, 10); 92 | } 93 | catch (Exception ex) 94 | { 95 | Console.WriteLine(ex.Message); 96 | } 97 | finally 98 | { 99 | // Wait for user stop action. 100 | Console.WriteLine("Press any key to stop..."); 101 | Console.ReadKey(); 102 | } 103 | } 104 | 105 | #region Utility methods 106 | 107 | private static void ShowHistogram(IList values, int count, double? maxValue = null) 108 | { 109 | // Calculate mean value. 110 | var mean = values.Aggregate((s, v) => s + v) / values.Count; 111 | Console.WriteLine("Mean latency = {0:F3}mcs", mean); 112 | 113 | // Calculate bounds values. 114 | var bound99 = (int) (values.Count * 99.0 / 100.0); 115 | Console.WriteLine("99% observations less than = {0:F3}mcs", values[bound99]); 116 | var bound9999 = (int) (values.Count * 99.99 / 100.0); 117 | Console.WriteLine("99.99% observations less than = {0:F3}mcs", values[bound9999]); 118 | 119 | var min = values[0]; 120 | var max = maxValue ?? values[bound99]; 121 | var step = (max - min) / count; 122 | 123 | for (var i = 0; i < count; i++) 124 | { 125 | var lower = min + i * step; 126 | var upper = min + (i + 1) * step; 127 | Console.WriteLine("{0}) {1:F3} - {2:F4} = {3}", i, lower, upper, 128 | values.Count(v => v >= lower && v <= upper)); 129 | } 130 | } 131 | 132 | #endregion 133 | } 134 | } -------------------------------------------------------------------------------- /LoggingPerformance.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 15 4 | VisualStudioVersion = 15.0.27703.2026 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LoggingPerformance.Serilog", "LoggingPerformance.Serilog\LoggingPerformance.Serilog.csproj", "{8C0236B3-A8A7-4D49-84A4-CCBEBBCD0956}" 7 | EndProject 8 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LoggingPerformance.NLog", "LoggingPerformance.NLog\LoggingPerformance.NLog.csproj", "{5996F906-257C-4C07-91EB-FEFCF8411D09}" 9 | EndProject 10 | Global 11 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 12 | Debug|Any CPU = Debug|Any CPU 13 | Release|Any CPU = Release|Any CPU 14 | EndGlobalSection 15 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 16 | {8C0236B3-A8A7-4D49-84A4-CCBEBBCD0956}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 17 | {8C0236B3-A8A7-4D49-84A4-CCBEBBCD0956}.Debug|Any CPU.Build.0 = Debug|Any CPU 18 | {8C0236B3-A8A7-4D49-84A4-CCBEBBCD0956}.Release|Any CPU.ActiveCfg = Release|Any CPU 19 | {8C0236B3-A8A7-4D49-84A4-CCBEBBCD0956}.Release|Any CPU.Build.0 = Release|Any CPU 20 | {5996F906-257C-4C07-91EB-FEFCF8411D09}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 21 | {5996F906-257C-4C07-91EB-FEFCF8411D09}.Debug|Any CPU.Build.0 = Debug|Any CPU 22 | {5996F906-257C-4C07-91EB-FEFCF8411D09}.Release|Any CPU.ActiveCfg = Release|Any CPU 23 | {5996F906-257C-4C07-91EB-FEFCF8411D09}.Release|Any CPU.Build.0 = Release|Any CPU 24 | EndGlobalSection 25 | GlobalSection(SolutionProperties) = preSolution 26 | HideSolutionNode = FALSE 27 | EndGlobalSection 28 | GlobalSection(ExtensibilityGlobals) = postSolution 29 | SolutionGuid = {7CCDEEA0-F32A-4767-89DD-4580195FBE83} 30 | EndGlobalSection 31 | EndGlobal 32 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ### Summary 2 | Logging performance comparison between Serilog and NLog. 3 | 4 | ### Dev info 5 | 6 | 1. Windows 10 Education x64 7 | 2. Microsoft Visual Studio Enterprise 2017 15.7.3 8 | 3. .NET Core 2.0 9 | 10 | ### Computer infomation 11 | 12 | 1. Intel i5-7500 3.40GHz 13 | 2. 16GB 14 | 3. Intel 600P 256G 15 | 16 | ### Involving library 17 | 18 | 1. [LibLog](https://github.com/damianh/LibLog) 19 | 20 | ### Referenced document 21 | 22 | 1. [Serilog vs NLog Benchmarks](https://www.darylcumbo.net/serilog-vs-nlog-benchmarks/) 23 | 24 | 2. [.NET low latency logging. Part 1 - Testing environment, Sample application, Best performance!](https://deep-depth.blogspot.com/2014/01/choose-solution-for-low-latency-logging.html) 25 | 26 | # Benchmarks 1 27 | 28 | ### Arrange 29 | 30 | Write target: File 31 | Test input count: 1000000 32 | Producer: 1 33 | 34 | ### Serilog 35 | 36 | Generated 1000000 values in 3506ms (throughput = 285199.451 ops per second) 37 | Mean latency = 3.474mcs 38 | 99% observations less than = 15.624mcs 39 | 99.99% observations less than = 125.596mcs 40 | 0) 2.404 - 3.7258 = 950441 41 | 1) 3.726 - 5.0479 = 15937 42 | 2) 5.048 - 6.3699 = 2294 43 | 3) 6.370 - 7.6920 = 3218 44 | 4) 7.692 - 9.0141 = 10559 45 | 5) 9.014 - 10.3361 = 1593 46 | 6) 10.336 - 11.6582 = 630 47 | 7) 11.658 - 12.9803 = 705 48 | 8) 12.980 - 14.3023 = 466 49 | 9) 14.302 - 15.6244 = 5128 50 | 51 | ### NLog 52 | 53 | Generated 1000000 values in 7256ms (throughput = 137812.554 ops per second) 54 | Mean latency = 7.225mcs 55 | 99% observations less than = 434.178mcs 56 | 99.99% observations less than = 1055.547mcs 57 | 0) 0.901 - 44.2290 = 989657 58 | 1) 44.229 - 87.5566 = 46 59 | 2) 87.557 - 130.8843 = 12 60 | 3) 130.884 - 174.2119 = 230 61 | 4) 174.212 - 217.5395 = 43 62 | 5) 217.540 - 260.8671 = 6 63 | 6) 260.867 - 304.1948 = 1 64 | 7) 304.195 - 347.5224 = 2 65 | 8) 347.522 - 390.8500 = 0 66 | 9) 390.850 - 434.1776 = 5 67 | 68 | # Benchmarks 2 69 | 70 | ### Arrange 71 | 72 | Write target: File 73 | Test input count: 5000000 74 | Producer: 1 75 | 76 | ### Serilog 77 | 78 | Generated 5000000 values in 17053ms (throughput = 293191.681 ops per second) 79 | Mean latency = 3.381mcs 80 | 99% observations less than = 15.324mcs 81 | 99.99% observations less than = 120.789mcs 82 | 0) 2.404 - 3.6958 = 4746369 83 | 1) 3.696 - 4.9878 = 97342 84 | 2) 4.988 - 6.2798 = 7559 85 | 3) 6.280 - 7.5718 = 6611 86 | 4) 7.572 - 8.8638 = 58916 87 | 5) 8.864 - 10.1559 = 10432 88 | 6) 10.156 - 11.4479 = 3673 89 | 7) 11.448 - 12.7399 = 1609 90 | 8) 12.740 - 14.0319 = 1525 91 | 9) 14.032 - 15.3239 = 19770 92 | 93 | ### NLog 94 | 95 | Generated 5000000 values in 38294ms (throughput = 130567.331 ops per second) 96 | Mean latency = 7.628mcs 97 | 99% observations less than = 462.422mcs 98 | 99.99% observations less than = 1126.458mcs 99 | 0) 0.901 - 47.0534 = 4947863 100 | 1) 47.053 - 93.2055 = 445 101 | 2) 93.205 - 139.3575 = 825 102 | 3) 139.357 - 185.5095 = 684 103 | 4) 185.510 - 231.6616 = 116 104 | 5) 231.662 - 277.8136 = 29 105 | 6) 277.814 - 323.9656 = 16 106 | 7) 323.966 - 370.1176 = 5 107 | 8) 370.118 - 416.2697 = 1 108 | 9) 416.270 - 462.4217 = 17 --------------------------------------------------------------------------------