In my .NET 6 web application I'm using the following infrastructure to log various events and exceptions:
- Microsoft.Extensions.Logging as logging API
- Serilog as logging framework
- MS SQL database as loging sink (i.e. the target where the logs are going to be written).
In the API layer of the web application there's a middleware that catches all exceptions, logs them and returns the exception message as JSON string to the client.
Together with the exception message I'd like to return also the ID of the created log-entry to the client. Unfortunately, the methods of Microsoft.Extensions.Logging's LoggerExtension
class (e.g. LogError()
) don't return any value. Is there any way to obtain the ID of the created database record?