Skip to content

Commit

Permalink
Update README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
marklauter authored May 10, 2024
1 parent c8e9855 commit c039afb
Showing 1 changed file with 42 additions and 0 deletions.
42 changes: 42 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,45 @@ public static IRequestHandler<TRequest, TResponse> UseSerilogRequestLogging<TReq
Action<RequestLoggerOptions<TRequest, TResponse>> configureOptions)
where TRequest : class`
```

## Sample Usage
```csharp
using Microsoft.Extensions.DependencyInjection;
using Plumber;
using Plumber.Serilog.Extensions;
using Serilog;
using Serilog.Events;
using Serilog.Exceptions;
using Serilog.Formatting.Compact;

var request = "Hello, World!";

Log.Logger = new LoggerConfiguration()
.MinimumLevel.Verbose()
.Enrich.FromLogContext()
.Enrich.WithExceptionDetails()
.WriteTo.Console(new CompactJsonFormatter())
.CreateLogger();

var handlerBuilder = RequestHandlerBuilder.New<string, string>();

_ = handlerBuilder.Services
.AddSerilog()
.AddLogging(loggingBuilder => loggingBuilder.AddSerilog());

var handler = handlerBuilder.Build();

_ = handler
.UseSerilogRequestLogging(options =>
{
options.LogLevel = LogEventLevel.Information;
options.EnrichDiagnosticContext = (diagnosticContext, context) =>
{
diagnosticContext.Set(nameof(context.Request), context.Request);
diagnosticContext.Set(nameof(context.Response), context.Response);
};
})
.Use<ToLowerMiddleware>();

var response = await handler.InvokeAsync(request);
```

0 comments on commit c039afb

Please sign in to comment.