Consolidate logging
gingters opened this issue · 3 comments
Make logging similar to what is done in .NET:
One nested Log
class with all [LoggerMessage]
definitions on it. EventId is counted from 1 per logging class.
Logging class is either scoped per project or even per single class when there are a lot of messages.
Examples: See HttpConnectionDispatcher.Log and HttpConnectionManager.Log in SignalR Core.
Also, while at it, add a scope (ILogger.BeginScope
) to all endpoints (RelayMiddleware, Body endpoint) that adds at least the RelayRequestId
(see #402 ) to the scope.
That way, ASP.NET Core internal logs (i.e. also EF) will also add the corresponding RelayRequestId to the logging system.
We decided to make the EventId unique per project in an internal static class just like this:
https://github.com/dotnet/aspnetcore/blob/0684c8aa38c6b9926bae3d901741a83c453dc413/src/Servers/HttpSys/src/LoggerEventIds.cs
We then create a partial class for all LoggerMessages on each type: {ClassName}.Log.cs
like this:
https://github.com/dotnet/aspnetcore/blob/0684c8aa38c6b9926bae3d901741a83c453dc413/src/Servers/HttpSys/src/HttpSysListener.Log.cs#L12
Usage is then like this:
https://github.com/dotnet/aspnetcore/blob/main/src/Servers/HttpSys/src/HttpSysListener.cs#L238
We should also solve the todos regarding dotnet/runtime#69490 as this is fixed already.