diff --git a/Build.ps1 b/Build.ps1
index 0687e20..a674b52 100644
--- a/Build.ps1
+++ b/Build.ps1
@@ -11,7 +11,7 @@ if(Test-Path .\artifacts) {
$branch = @{ $true = $env:APPVEYOR_REPO_BRANCH; $false = $(git symbolic-ref --short -q HEAD) }[$env:APPVEYOR_REPO_BRANCH -ne $NULL];
$revision = @{ $true = "{0:00000}" -f [convert]::ToInt32("0" + $env:APPVEYOR_BUILD_NUMBER, 10); $false = "local" }[$env:APPVEYOR_BUILD_NUMBER -ne $NULL];
-$suffix = @{ $true = ""; $false = "$($branch.Substring(0, [math]::Min(10,$branch.Length)))-$revision"}[$branch -eq "master" -and $revision -ne "local"]
+$suffix = @{ $true = ""; $false = "$($branch.Substring(0, [math]::Min(10,$branch.Length)))-$revision"}[$branch -eq "main" -and $revision -ne "local"]
echo "build: Version suffix is $suffix"
diff --git a/Directory.Build.props b/Directory.Build.props
index 3883932..2b620bc 100644
--- a/Directory.Build.props
+++ b/Directory.Build.props
@@ -7,7 +7,6 @@
$(MSBuildThisFileDirectory)assets/Serilog.snk
true
enable
- enable
-
\ No newline at end of file
+
diff --git a/README.md b/README.md
index 9649d58..bbed04e 100644
--- a/README.md
+++ b/README.md
@@ -1,4 +1,4 @@
-# Serilog.Extensions.Logging [![Build status](https://ci.appveyor.com/api/projects/status/865nohxfiq1rnby0/branch/master?svg=true)](https://ci.appveyor.com/project/serilog/serilog-framework-logging/history) [![NuGet Version](http://img.shields.io/nuget/v/Serilog.Extensions.Logging.svg?style=flat)](https://www.nuget.org/packages/Serilog.Extensions.Logging/)
+# Serilog.Extensions.Logging [![Build status](https://ci.appveyor.com/api/projects/status/865nohxfiq1rnby0/branch/master?svg=true)](https://ci.appveyor.com/project/serilog/serilog-framework-logging/history) [![NuGet Version](http://img.shields.io/nuget/v/Serilog.Extensions.Logging.svg?style=flat)](https://www.nuget.org/packages/Serilog.Extensions.Logging/)
A Serilog provider for [Microsoft.Extensions.Logging](https://www.nuget.org/packages/Microsoft.Extensions.Logging), the logging subsystem used by ASP.NET Core.
@@ -16,9 +16,9 @@ The package implements `AddSerilog()` on `ILoggingBuilder` and `ILoggerFactory`
**First**, install the _Serilog.Extensions.Logging_ [NuGet package](https://www.nuget.org/packages/Serilog.Extensions.Logging) into your web or console app. You will need a way to view the log messages - _Serilog.Sinks.Console_ writes these to the console.
-```powershell
-Install-Package Serilog.Extensions.Logging -DependencyVersion Highest
-Install-Package Serilog.Sinks.Console
+```sh
+dotnet add package Serilog.Extensions.Logging
+dotnet add package Serilog.Sinks.Console
```
**Next**, in your application's `Startup` method, configure Serilog first:
@@ -34,7 +34,7 @@ public class Startup
.Enrich.FromLogContext()
.WriteTo.Console()
.CreateLogger();
-
+
// Other startup code
```
@@ -46,7 +46,7 @@ call `AddSerilog()` on the provided `loggingBuilder`.
{
services.AddLogging(loggingBuilder =>
loggingBuilder.AddSerilog(dispose: true));
-
+
// Other services ...
}
```
@@ -60,7 +60,7 @@ call `AddSerilog()` on the provided `loggingBuilder`.
IApplicationLifetime appLifetime)
{
loggerfactory.AddSerilog();
-
+
// Ensure any buffered events are sent at shutdown
appLifetime.ApplicationStopped.Register(Log.CloseAndFlush);
```
@@ -69,7 +69,7 @@ That's it! With the level bumped up a little you should see log output like:
```
[22:14:44.646 DBG] RouteCollection.RouteAsync
- Routes:
+ Routes:
Microsoft.AspNet.Mvc.Routing.AttributeRoute
{controller=Home}/{action=Index}/{id?}
Handled? True
@@ -144,6 +144,10 @@ using (_logger.BeginScope(scopeProps) {
// }
```
+### Versioning
+
+This package tracks the versioning and target framework support of its [_Microsoft.Extensions.Logging_](https://nuget.org/packages/Microsoft.Extensions.Logging) dependency.
+
### Credits
This package evolved from an earlier package _Microsoft.Framework.Logging.Serilog_ [provided by the ASP.NET team](https://github.com/aspnet/Logging/pull/182).
diff --git a/appveyor.yml b/appveyor.yml
index e6e8a2f..3e4a484 100644
--- a/appveyor.yml
+++ b/appveyor.yml
@@ -14,12 +14,12 @@ deploy:
secure: EN9f+XXE3fW+ebL4wxrIbafdtbNvRfddBN8UUixvctYh4qMBHzr1JdnM83QsM1zo
skip_symbols: true
on:
- branch: /^(master|dev)$/
+ branch: /^(main|dev)$/
- provider: GitHub
auth_token:
secure: p4LpVhBKxGS5WqucHxFQ5c7C8cP74kbNB0Z8k9Oxx/PMaDQ1+ibmoexNqVU5ZlmX
artifact: /Serilog.*\.nupkg/
tag: v$(appveyor_build_version)
on:
- branch: master
+ branch: main
diff --git a/samples/Sample/Program.cs b/samples/Sample/Program.cs
index 9ba6bf0..d70b9aa 100644
--- a/samples/Sample/Program.cs
+++ b/samples/Sample/Program.cs
@@ -3,75 +3,66 @@
using Serilog;
using Serilog.Extensions.Logging;
-namespace Sample;
+// Creating a `LoggerProviderCollection` lets Serilog optionally write
+// events through other dynamically-added MEL ILoggerProviders.
+var providers = new LoggerProviderCollection();
-public class Program
-{
- public static void Main(string[] args)
- {
- // Creating a `LoggerProviderCollection` lets Serilog optionally write
- // events through other dynamically-added MEL ILoggerProviders.
- var providers = new LoggerProviderCollection();
-
- Log.Logger = new LoggerConfiguration()
- .MinimumLevel.Debug()
- .WriteTo.Console()
- .WriteTo.Providers(providers)
- .CreateLogger();
+Log.Logger = new LoggerConfiguration()
+ .MinimumLevel.Debug()
+ .WriteTo.Console()
+ .WriteTo.Providers(providers)
+ .CreateLogger();
- var services = new ServiceCollection();
+var services = new ServiceCollection();
- services.AddSingleton(providers);
- services.AddSingleton(sc =>
- {
- var providerCollection = sc.GetService();
- var factory = new SerilogLoggerFactory(null, true, providerCollection);
+services.AddSingleton(providers);
+services.AddSingleton(sc =>
+{
+ var providerCollection = sc.GetService();
+ var factory = new SerilogLoggerFactory(null, true, providerCollection);
- foreach (var provider in sc.GetServices())
- factory.AddProvider(provider);
+ foreach (var provider in sc.GetServices())
+ factory.AddProvider(provider);
- return factory;
- });
+ return factory;
+});
- services.AddLogging(l => l.AddConsole());
+services.AddLogging(l => l.AddConsole());
- var serviceProvider = services.BuildServiceProvider();
- var logger = serviceProvider.GetRequiredService>();
+var serviceProvider = services.BuildServiceProvider();
+var logger = serviceProvider.GetRequiredService>();
- var startTime = DateTimeOffset.UtcNow;
- logger.LogInformation(1, "Started at {StartTime} and 0x{Hello:X} is hex of 42", startTime, 42);
+var startTime = DateTimeOffset.UtcNow;
+logger.LogInformation(1, "Started at {StartTime} and 0x{Hello:X} is hex of 42", startTime, 42);
- try
- {
- throw new Exception("Boom!");
- }
- catch (Exception ex)
- {
- logger.LogCritical("Unexpected critical error starting application", ex);
- logger.Log(LogLevel.Critical, 0, "Unexpected critical error", ex, null!);
- // This write should not log anything
- logger.Log