Skip to content

Commit 7c91749

Browse files
authored
Add Azure Diagnostic Logs Streaming example [Skip CI]
1 parent 0d2d6d0 commit 7c91749

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

README.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,3 +102,31 @@ You can alternatively configure Serilog using a delegate as shown below:
102102
This has the advantage of making the `hostingContext`'s `Configuration` object available for configuration of the logger, but at the expense of recording `Exception`s raised earlier in program startup.
103103

104104
If this method is used, `Log.Logger` is assigned implicitly, and closed when the app is shut down.
105+
106+
### Writing to the Azure Diagnostics Log Stream
107+
108+
The Azure Diagnostic Log Stream ships events from any files in the `D:\home\LogFiles\` folder. To enable this for your app, first install the _Serilog.Sinks.File_ package:
109+
110+
```powershell
111+
Install-Package Serilog.Sinks.File
112+
```
113+
114+
Then add a file sink to your `LoggerConfiguration`, taking care to set the `shared` and `flushToDiskInterval` parameters:
115+
116+
```csharp
117+
public static int Main(string[] args)
118+
{
119+
Log.Logger = new LoggerConfiguration()
120+
.MinimumLevel.Debug()
121+
.MinimumLevel.Override("Microsoft", LogEventLevel.Information)
122+
.Enrich.FromLogContext()
123+
.WriteTo.Console()
124+
// Add this line:
125+
.WriteTo.File(
126+
@"D:\home\LogFiles\Application\myapp.txt",
127+
fileSizeLimitBytes: 1_000_000,
128+
rollOnFileSizeLimit: true,
129+
shared: true,
130+
flushToDiskInterval: TimeSpan.FromSeconds(1))
131+
.CreateLogger();
132+
```

0 commit comments

Comments
 (0)