Skip to content

Commit 79a74c8

Browse files
authored
Merge pull request #54 from mmarinchenko/patch-1
Update README to ASP.NET Core 6.0
2 parents 7c49f45 + 4497e3b commit 79a74c8

File tree

1 file changed

+27
-11
lines changed

1 file changed

+27
-11
lines changed

README.md

+27-11
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
# Serilog.Extensions.Logging.File [![NuGet Pre Release](https://img.shields.io/nuget/vpre/Serilog.Extensions.Logging.File.svg)](https://nuget.org/packages/Serilog.Extensions.Logging.File) [![Join the chat at https://gitter.im/serilog/serilog](https://img.shields.io/gitter/room/serilog/serilog.svg)](https://gitter.im/serilog/serilog) [![Build status](https://ci.appveyor.com/api/projects/status/rdff6bp9oeqfxif7?svg=true)](https://ci.appveyor.com/project/serilog/serilog-extensions-logging-file)
22

3-
This package makes it a one-liner - `loggerFactory.AddFile()` - to configure top-quality file logging for ASP.NET Core apps.
3+
This package makes it a one-liner - `loggingBuilder.AddFile()` - to configure top-quality file logging for ASP.NET Core apps.
44

55
* Text or JSON file output
66
* Files roll over on date; capped file size
77
* Request ids and event ids included with each message
8-
* Writes are performed on a background thread
8+
* Log writes are performed asynchronously
99
* Files are periodically flushed to disk (required for Azure App Service log collection)
1010
* Fast, stable, battle-proven logging code courtesy of [Serilog](https://serilog.net)
1111

@@ -19,18 +19,34 @@ You can get started quickly with this package, and later migrate to the full Ser
1919
<PackageReference Include="Serilog.Extensions.Logging.File" Version="3.0.0" />
2020
```
2121

22-
**2.** In your `Program` class, configure logging on the web host builder, and call `AddFile()` on the provided `loggingBuilder`.
22+
**2.** In your `Program` class, configure logging on the host builder, and call `AddFile()` on the provided `loggingBuilder`:
2323

2424
```csharp
25-
WebHost.CreateDefaultBuilder(args)
26-
.ConfigureLogging((hostingContext, builder) =>
25+
Host.CreateDefaultBuilder(args)
26+
.ConfigureWebHostDefaults(webHost =>
2727
{
28-
builder.AddFile("Logs/myapp-{Date}.txt");
28+
webHost.UseStartup<Startup>();
29+
})
30+
.ConfigureLogging((hostingContext, loggingBuilder) =>
31+
{
32+
loggingBuilder.AddFile("Logs/myapp-{Date}.txt");
2933
})
30-
.UseStartup<Startup>()
3134
.Build();
3235
```
3336

37+
Or, alternatively, with [Minimal APIs](https://docs.microsoft.com/en-us/aspnet/core/fundamentals/minimal-apis):
38+
39+
```csharp
40+
var builder = WebApplication.CreateBuilder(args);
41+
42+
builder.Logging.AddFile("Logs/myapp-{Date}.txt");
43+
// Add other services to the container.
44+
<...>
45+
46+
var app = builder.Build();
47+
<...>
48+
```
49+
3450
**Done!** The framework will inject `ILogger` instances into controllers and other classes:
3551

3652
```csharp
@@ -144,7 +160,7 @@ In `appsettings.json` add a `"Logging"` property:
144160
And then pass the configuration section to the `AddFile()` method:
145161

146162
```csharp
147-
loggingBuilder.AddFile(Configuration.GetSection("Logging"));
163+
loggingBuilder.AddFile(hostingContext.Configuration.GetSection("Logging"));
148164
```
149165

150166
In addition to the properties shown above, the `"Logging"` configuration supports:
@@ -160,12 +176,12 @@ In addition to the properties shown above, the `"Logging"` configuration support
160176

161177
This package is opinionated, providing the most common/recommended options supported by Serilog. For more sophisticated configuration, using Serilog directly is recommened. See the instructions in [Serilog.AspNetCore](https://github.com/serilog/serilog-aspnetcore) to get started.
162178

163-
The following packages are used to provide `AddFile()`:
179+
The following packages are used to provide `loggingBuilder.AddFile()`:
164180

165181
* [Serilog](https://github.com/serilog/serilog) - the core logging pipeline
166-
* [Serilog.Sinks.RollingFile](https://github.com/serilog/serilog-sinks-rollingfile) - rolling file output
167182
* [Serilog.Formatting.Compact](https://github.com/serilog/serilog-formatting-compact) - JSON event formatting
168183
* [Serilog.Extensions.Logging](https://github.com/serilog/serilog-extensions-logging) - ASP.NET Core integration
169-
* [Serilog.Sinks.Async](https://github.com/serilog/serilog-sinks-async) - async wrapper to perform log writes on a background thread
184+
* [Serilog.Sinks.Async](https://github.com/serilog/serilog-sinks-async) - wrapper to perform log writes asynchronously
185+
* [Serilog.Sinks.RollingFile](https://github.com/serilog/serilog-sinks-rollingfile) - rolling file output
170186

171187
If you decide to switch to the full Serilog API and need help, please drop into the [Gitter channel](https://gitter.im/serilog/serilog) or post your question on [Stack Overflow](http://stackoverflow.com/questions/tagged/serilog).

0 commit comments

Comments
 (0)