feat(logging): Adds support for Serilog (#573)
Example:
```cs
public class SomeClass
{
private static ILogger _logger;
private static Logger => _logger ??= LogFactory.GetLogger(typeof(SomeClass));
...
}
```
This commit is contained in:
parent
5e1ec5416d
commit
3a619e0103
29 changed files with 347 additions and 176 deletions
|
|
@ -0,0 +1,63 @@
|
|||
using System;
|
||||
using BenchmarkDotNet.Attributes;
|
||||
using BenchmarkDotNet.Jobs;
|
||||
using Serilog;
|
||||
using Serilog.Core;
|
||||
|
||||
namespace Benchmarks
|
||||
{
|
||||
[SimpleJob(RuntimeMoniker.NetCoreApp50)]
|
||||
public class BenchmarkConsoleLogging
|
||||
{
|
||||
private const string text = "Sample message";
|
||||
|
||||
private Logger logger;
|
||||
private Logger asyncLogger;
|
||||
|
||||
[IterationSetup]
|
||||
public void IterationSetup()
|
||||
{
|
||||
logger = new LoggerConfiguration()
|
||||
.WriteTo.Console()
|
||||
.CreateLogger();
|
||||
|
||||
asyncLogger = new LoggerConfiguration()
|
||||
.WriteTo.Async(a => a.Console())
|
||||
.CreateLogger();
|
||||
}
|
||||
|
||||
[IterationCleanup]
|
||||
public void IterationCleanup()
|
||||
{
|
||||
logger = null;
|
||||
asyncLogger = null;
|
||||
}
|
||||
|
||||
[Benchmark]
|
||||
public void TestConsoleWriteLine()
|
||||
{
|
||||
for (int i = 0; i < 100; i++)
|
||||
{
|
||||
Console.WriteLine(text);
|
||||
}
|
||||
}
|
||||
|
||||
[Benchmark]
|
||||
public void TestSerilogConsoleSink()
|
||||
{
|
||||
for (int i = 0; i < 100; i++)
|
||||
{
|
||||
logger.Information(text);
|
||||
}
|
||||
}
|
||||
|
||||
[Benchmark]
|
||||
public void TestSerilogAsyncConsoleSink()
|
||||
{
|
||||
for (int i = 0; i < 100; i++)
|
||||
{
|
||||
asyncLogger.Information(text);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue