serilog-aspnetcore icon indicating copy to clipboard operation
serilog-aspnetcore copied to clipboard

Add EnrichDiagnosticContextAsync as async addition

Open hbunjes opened this issue 2 years ago • 1 comments

Is your feature request related to a problem? Please describe. I want to enrich the http logging with Serilog by parts of the request body. Therefore, I read from the request body which must be done async. However, if a set EnrichDiagnosticContext to an async method like the following I get the VSTHRD101 warning:

options.EnrichDiagnosticContext = async (context, httpContext) =>
    {
        await LogHelper.EnrichFromRequestAsync(context, httpContext);
    };

Describe the solution you'd like In addition to the Action<IDiagnosticContext, HttpContext>? EnrichDiagnosticContext, there should be a Func<IDiagnosticContext, HttpContext, Task>? EnrichDiagnosticContextAsync that can be called asynchronously and returns just a Task.

hbunjes avatar Sep 18 '23 12:09 hbunjes

I've added a PR to resolve this.

hbunjes avatar Sep 20 '23 07:09 hbunjes