-
Notifications
You must be signed in to change notification settings - Fork 72
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #157 from nblumhardt/serilog-4
Update to Serilog 4, file scoped namespaces
- Loading branch information
Showing
47 changed files
with
1,647 additions
and
1,724 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,57 +1,47 @@ | ||
using Serilog; | ||
using Serilog.Sinks.SystemConsole.Themes; | ||
using System; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
|
||
namespace SyncWritesDemo | ||
Console.WriteLine("A sample of how to sync writes to the console sink."); | ||
|
||
if (args is { Length: 1 }) | ||
{ | ||
public static class Program | ||
switch (args[0]) | ||
{ | ||
public static void Main(string[] args) | ||
{ | ||
Console.WriteLine("A sample of how to sync writes to the console sink."); | ||
|
||
if (args != null && args.Length == 1) | ||
{ | ||
switch (args[0]) | ||
{ | ||
case "--sync-root-default": | ||
SystemConsoleSyncTest(syncRootForLogger1: null, syncRootForLogger2: null); | ||
return; | ||
case "--sync-root-separate": | ||
SystemConsoleSyncTest(syncRootForLogger1: new object(), syncRootForLogger2: new object()); | ||
return; | ||
case "--sync-root-same": | ||
var sameSyncRoot = new object(); | ||
SystemConsoleSyncTest(syncRootForLogger1: sameSyncRoot, syncRootForLogger2: sameSyncRoot); | ||
return; | ||
} | ||
} | ||
case "--sync-root-default": | ||
SystemConsoleSyncTest(syncRootForLogger1: null, syncRootForLogger2: null); | ||
return; | ||
case "--sync-root-separate": | ||
SystemConsoleSyncTest(syncRootForLogger1: new object(), syncRootForLogger2: new object()); | ||
return; | ||
case "--sync-root-same": | ||
var sameSyncRoot = new object(); | ||
SystemConsoleSyncTest(syncRootForLogger1: sameSyncRoot, syncRootForLogger2: sameSyncRoot); | ||
return; | ||
} | ||
} | ||
|
||
Console.WriteLine("Expecting one of the following arguments:{0}--sync-root-default{0}--sync-root-separate{0}--sync-root-same", Environment.NewLine); | ||
} | ||
Console.WriteLine("Expecting one of the following arguments:{0}--sync-root-default{0}--sync-root-separate{0}--sync-root-same", Environment.NewLine); | ||
|
||
static void SystemConsoleSyncTest(object syncRootForLogger1, object syncRootForLogger2) | ||
{ | ||
var logger1 = new LoggerConfiguration() | ||
.MinimumLevel.Verbose() | ||
.Enrich.WithProperty("Logger", "logger1") | ||
.WriteTo.Console(theme: SystemConsoleTheme.Literate, syncRoot: syncRootForLogger1) | ||
.CreateLogger(); | ||
static void SystemConsoleSyncTest(object syncRootForLogger1, object syncRootForLogger2) | ||
{ | ||
var logger1 = new LoggerConfiguration() | ||
.MinimumLevel.Verbose() | ||
.Enrich.WithProperty("Logger", "logger1") | ||
.WriteTo.Console(theme: SystemConsoleTheme.Literate, syncRoot: syncRootForLogger1) | ||
.CreateLogger(); | ||
|
||
var logger2 = new LoggerConfiguration() | ||
.MinimumLevel.Verbose() | ||
.Enrich.WithProperty("Logger", "logger2") | ||
.WriteTo.Console(theme: SystemConsoleTheme.Literate, syncRoot: syncRootForLogger2) | ||
.CreateLogger(); | ||
var logger2 = new LoggerConfiguration() | ||
.MinimumLevel.Verbose() | ||
.Enrich.WithProperty("Logger", "logger2") | ||
.WriteTo.Console(theme: SystemConsoleTheme.Literate, syncRoot: syncRootForLogger2) | ||
.CreateLogger(); | ||
|
||
var options = new ParallelOptions { MaxDegreeOfParallelism = 8 }; | ||
Parallel.For(0, 1000, options, (i, loopState) => | ||
{ | ||
var logger = (i % 2 == 0) ? logger1 : logger2; | ||
logger.Information("Event {Iteration} generated by {ThreadId}", i, Thread.CurrentThread.ManagedThreadId); | ||
}); | ||
} | ||
} | ||
var options = new ParallelOptions { MaxDegreeOfParallelism = 8 }; | ||
Parallel.For(0, 1000, options, (i, _) => | ||
{ | ||
var logger = i % 2 == 0 ? logger1 : logger2; | ||
logger.Information("Event {Iteration} generated by {ThreadId}", i, Environment.CurrentManagedThreadId); | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.