You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
**Next**, in your application's _Program.cs_ file, configure Serilog first:
15
+
**Next**, in your application's _Program.cs_ file, configure Serilog first. A `try`/`catch` block will ensure any configuration issues are appropriately logged:
16
16
17
17
```csharp
18
18
publicclassProgram
@@ -25,25 +25,11 @@ public class Program
25
25
.Enrich.FromLogContext()
26
26
.WriteTo.Console()
27
27
.CreateLogger();
28
-
```
29
-
30
-
Then, add `UseSerilog()` tothewebhostbuilder. A `try`/`catch` blockwillensureanyconfigurationissuesareappropriatelylogged:
31
28
32
-
```csharp
33
29
try
34
30
{
35
31
Log.Information("Starting web host");
36
-
37
-
varhost=newWebHostBuilder()
38
-
.UseKestrel()
39
-
.UseContentRoot(Directory.GetCurrentDirectory())
40
-
.UseIISIntegration()
41
-
.UseStartup<Startup>()
42
-
.UseSerilog() // <-- Add this line
43
-
.Build();
44
-
45
-
host.Run();
46
-
32
+
BuildWebHost(args).Run();
47
33
return0;
48
34
}
49
35
catch (Exceptionex)
@@ -56,6 +42,16 @@ Then, add `UseSerilog()` to the web host builder. A `try`/`catch` block will ens
@@ -83,6 +79,8 @@ That's it! With the level bumped up a little you will see log output like:
83
79
84
80
Tip: to see Serilog output in the Visual Studio output window when running under IIS, select _ASP.NET Core Web Server_ from the _Show output from_ drop-down list.
85
81
82
+
A more complete example, showing _appsettings.json_ configuration, can be found in [the sample project here](https://github.com/serilog/serilog-aspnetcore/tree/dev/samples/SimpleWebSample).
83
+
86
84
### Using the package
87
85
88
86
With _Serilog.AspNetCore_ installed and configured, you can write log messages directly through Serilog or any `ILogger` interface injected by ASP.NET. All loggers will use the same underlying implementation, levels, and destinations.
0 commit comments