NethermindEth / dotnet-libp2p

A libp2p implementation for .NET in C#.
MIT License
62 stars 24 forks source link

Improve logging #41

Open flcl42 opened 1 year ago

flcl42 commented 1 year ago
chertby commented 1 year ago

I would like to propose the implementation of an EventId system for our logs, which will consist of six digits.

The first three digits will be related to a specific project:

The last three digits will determine the log level and the log's ID:

For example, the complete EventId for the Ping protocol could be 200100.

This system will provide a clear and structured way to identify events in our logs, making it easier to track and troubleshoot issues.

Please feel free to share your thoughts and feedback on this proposal.

I will prepare a PR for the Ping protocol to make it more clear. @flcl42

flcl42 commented 12 months ago

@chertby it's good to have some structure but it seems like complication for potential contributors, another rule to keep in mind. Let's start by having just incremental numbers for the messages which is already a lot.

chertby commented 12 months ago

@flcl42 I’ll prepare a simpler version today.

chertby commented 11 months ago

I still suggest leaving different event IDs for different protocols. But then use a simple increment. Use the name of the function itself as an event hire.

It’s simpler than the previous option, but we keep good logging, which should help with debugging.

I updated PR

private const int EventId = 200_000;

[LoggerMessage(
    EventId = EventId + 1,
    EventName = nameof(ReadingPong),
    Message = "Reading pong",
    Level = LogLevel.Trace)]
internal static partial void ReadingPong(
    this ILogger logger);

[LoggerMessage(
    EventId = EventId + 2,
    EventName = nameof(VerifyingPong),
    Message = "Verifying pong",
    Level = LogLevel.Trace)]
internal static partial void VerifyingPong(
    this ILogger logger);