Skip to content

Commit fa07aaf

Browse files
committed
Update to Serilog 4, file scoped namespaces
1 parent a9308ef commit fa07aaf

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+1655
-1715
lines changed

Build.ps1

Lines changed: 14 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,9 @@
1-
Write-Output "build: Build started"
2-
3-
& dotnet --info
4-
& dotnet --list-sdks
1+
echo "build: Build started"
52

63
Push-Location $PSScriptRoot
74

85
if(Test-Path .\artifacts) {
9-
Write-Output "build: Cleaning .\artifacts"
6+
echo "build: Cleaning .\artifacts"
107
Remove-Item .\artifacts -Force -Recurse
118
}
129

@@ -18,45 +15,34 @@ $suffix = @{ $true = ""; $false = "$($branch.Substring(0, [math]::Min(10,$branch
1815
$commitHash = $(git rev-parse --short HEAD)
1916
$buildSuffix = @{ $true = "$($suffix)-$($commitHash)"; $false = "$($branch)-$($commitHash)" }[$suffix -ne ""]
2017

21-
Write-Output "build: Package version suffix is $suffix"
22-
Write-Output "build: Build version suffix is $buildSuffix"
18+
echo "build: Package version suffix is $suffix"
19+
echo "build: Build version suffix is $buildSuffix"
2320

24-
foreach ($src in Get-ChildItem src/*) {
21+
foreach ($src in ls src/*) {
2522
Push-Location $src
2623

27-
Write-Output "build: Packaging project in $src"
24+
echo "build: Packaging project in $src"
2825

29-
& dotnet build -c Release --version-suffix=$buildSuffix
26+
& dotnet build -c Release --version-suffix=$buildSuffix -p:EnableSourceLink=true
3027
if ($suffix) {
31-
& dotnet pack -c Release --include-source -o ..\..\artifacts --version-suffix=$suffix --no-build
28+
& dotnet pack -c Release -o ..\..\artifacts --version-suffix=$suffix --no-build
3229
} else {
33-
& dotnet pack -c Release --include-source -o ..\..\artifacts --no-build
30+
& dotnet pack -c Release -o ..\..\artifacts --no-build
3431
}
35-
if($LASTEXITCODE -ne 0) { exit 1 }
36-
37-
Pop-Location
38-
}
39-
40-
foreach ($sample in Get-ChildItem sample/*) {
41-
Push-Location $sample
42-
43-
Write-Output "build: Testing project in $sample"
44-
45-
& dotnet build -c Release --version-suffix=$buildSuffix
46-
if($LASTEXITCODE -ne 0) { exit 3 }
32+
if($LASTEXITCODE -ne 0) { throw "build failed" }
4733

4834
Pop-Location
4935
}
5036

51-
foreach ($test in Get-ChildItem test/*.Tests) {
37+
foreach ($test in ls test/*.Tests) {
5238
Push-Location $test
5339

54-
Write-Output "build: Testing project in $test"
40+
echo "build: Testing project in $test"
5541

5642
& dotnet test -c Release
57-
if($LASTEXITCODE -ne 0) { exit 3 }
43+
if($LASTEXITCODE -ne 0) { throw "tests failed" }
5844

5945
Pop-Location
6046
}
6147

62-
Pop-Location
48+
Pop-Location

appveyor.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@ skip_tags: true
33
image: Visual Studio 2022
44
test: off
55
build_script:
6-
- ps: ./Build.ps1
6+
- pwsh: ./Build.ps1
77
artifacts:
88
- path: artifacts/Serilog.*.nupkg
99
deploy:
1010
- provider: NuGet
1111
api_key:
12-
secure: dX4ewxGxhiNURkqJPuZQ8GQNjLvb8oZrHBThVotn+9GSMyQzeKXFpHkN04ykOfgc
12+
secure: ZpUO4ECx4c/V0Ecj04cfV1UGd+ZABeEG9DDW2fjG8vITjNYhmbiiJH0qNOnRy2G3
1313
skip_symbols: true
1414
on:
1515
branch: /^(main|dev)$/

sample/ConsoleDemo/Program.cs

Lines changed: 24 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -3,38 +3,37 @@
33
using System;
44
using System.Threading;
55

6-
namespace ConsoleDemo
6+
namespace ConsoleDemo;
7+
8+
public static class Program
79
{
8-
public static class Program
10+
public static void Main()
911
{
10-
public static void Main()
11-
{
12-
Log.Logger = new LoggerConfiguration()
13-
.MinimumLevel.Verbose()
14-
.WriteTo.Console(theme: AnsiConsoleTheme.Code)
15-
.CreateLogger();
16-
17-
try
18-
{
19-
Log.Debug("Getting started");
12+
Log.Logger = new LoggerConfiguration()
13+
.MinimumLevel.Verbose()
14+
.WriteTo.Console(theme: AnsiConsoleTheme.Code)
15+
.CreateLogger();
2016

21-
Log.Information("Hello {Name} from thread {ThreadId}", Environment.GetEnvironmentVariable("USERNAME"), Thread.CurrentThread.ManagedThreadId);
17+
try
18+
{
19+
Log.Debug("Getting started");
2220

23-
Log.Warning("No coins remain at position {@Position}", new { Lat = 25, Long = 134 });
21+
Log.Information("Hello {Name} from thread {ThreadId}", Environment.GetEnvironmentVariable("USERNAME"), Thread.CurrentThread.ManagedThreadId);
2422

25-
Fail();
26-
}
27-
catch (Exception e)
28-
{
29-
Log.Error(e, "Something went wrong");
30-
}
23+
Log.Warning("No coins remain at position {@Position}", new { Lat = 25, Long = 134 });
3124

32-
Log.CloseAndFlush();
25+
Fail();
3326
}
34-
35-
static void Fail()
27+
catch (Exception e)
3628
{
37-
throw new DivideByZeroException();
29+
Log.Error(e, "Something went wrong");
3830
}
31+
32+
Log.CloseAndFlush();
33+
}
34+
35+
static void Fail()
36+
{
37+
throw new DivideByZeroException();
3938
}
40-
}
39+
}

sample/SyncWritesDemo/Program.cs

Lines changed: 40 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -4,54 +4,53 @@
44
using System.Threading;
55
using System.Threading.Tasks;
66

7-
namespace SyncWritesDemo
7+
namespace SyncWritesDemo;
8+
9+
public static class Program
810
{
9-
public static class Program
11+
public static void Main(string[] args)
1012
{
11-
public static void Main(string[] args)
12-
{
13-
Console.WriteLine("A sample of how to sync writes to the console sink.");
13+
Console.WriteLine("A sample of how to sync writes to the console sink.");
1414

15-
if (args != null && args.Length == 1)
15+
if (args != null && args.Length == 1)
16+
{
17+
switch (args[0])
1618
{
17-
switch (args[0])
18-
{
19-
case "--sync-root-default":
20-
SystemConsoleSyncTest(syncRootForLogger1: null, syncRootForLogger2: null);
21-
return;
22-
case "--sync-root-separate":
23-
SystemConsoleSyncTest(syncRootForLogger1: new object(), syncRootForLogger2: new object());
24-
return;
25-
case "--sync-root-same":
26-
var sameSyncRoot = new object();
27-
SystemConsoleSyncTest(syncRootForLogger1: sameSyncRoot, syncRootForLogger2: sameSyncRoot);
28-
return;
29-
}
19+
case "--sync-root-default":
20+
SystemConsoleSyncTest(syncRootForLogger1: null, syncRootForLogger2: null);
21+
return;
22+
case "--sync-root-separate":
23+
SystemConsoleSyncTest(syncRootForLogger1: new object(), syncRootForLogger2: new object());
24+
return;
25+
case "--sync-root-same":
26+
var sameSyncRoot = new object();
27+
SystemConsoleSyncTest(syncRootForLogger1: sameSyncRoot, syncRootForLogger2: sameSyncRoot);
28+
return;
3029
}
31-
32-
Console.WriteLine("Expecting one of the following arguments:{0}--sync-root-default{0}--sync-root-separate{0}--sync-root-same", Environment.NewLine);
3330
}
3431

35-
static void SystemConsoleSyncTest(object syncRootForLogger1, object syncRootForLogger2)
36-
{
37-
var logger1 = new LoggerConfiguration()
38-
.MinimumLevel.Verbose()
39-
.Enrich.WithProperty("Logger", "logger1")
40-
.WriteTo.Console(theme: SystemConsoleTheme.Literate, syncRoot: syncRootForLogger1)
41-
.CreateLogger();
32+
Console.WriteLine("Expecting one of the following arguments:{0}--sync-root-default{0}--sync-root-separate{0}--sync-root-same", Environment.NewLine);
33+
}
4234

43-
var logger2 = new LoggerConfiguration()
44-
.MinimumLevel.Verbose()
45-
.Enrich.WithProperty("Logger", "logger2")
46-
.WriteTo.Console(theme: SystemConsoleTheme.Literate, syncRoot: syncRootForLogger2)
47-
.CreateLogger();
35+
static void SystemConsoleSyncTest(object syncRootForLogger1, object syncRootForLogger2)
36+
{
37+
var logger1 = new LoggerConfiguration()
38+
.MinimumLevel.Verbose()
39+
.Enrich.WithProperty("Logger", "logger1")
40+
.WriteTo.Console(theme: SystemConsoleTheme.Literate, syncRoot: syncRootForLogger1)
41+
.CreateLogger();
4842

49-
var options = new ParallelOptions { MaxDegreeOfParallelism = 8 };
50-
Parallel.For(0, 1000, options, (i, loopState) =>
51-
{
52-
var logger = (i % 2 == 0) ? logger1 : logger2;
53-
logger.Information("Event {Iteration} generated by {ThreadId}", i, Thread.CurrentThread.ManagedThreadId);
54-
});
55-
}
43+
var logger2 = new LoggerConfiguration()
44+
.MinimumLevel.Verbose()
45+
.Enrich.WithProperty("Logger", "logger2")
46+
.WriteTo.Console(theme: SystemConsoleTheme.Literate, syncRoot: syncRootForLogger2)
47+
.CreateLogger();
48+
49+
var options = new ParallelOptions { MaxDegreeOfParallelism = 8 };
50+
Parallel.For(0, 1000, options, (i, loopState) =>
51+
{
52+
var logger = (i % 2 == 0) ? logger1 : logger2;
53+
logger.Information("Event {Iteration} generated by {ThreadId}", i, Thread.CurrentThread.ManagedThreadId);
54+
});
5655
}
57-
}
56+
}

0 commit comments

Comments
 (0)