EventId in logging

Finally I have realized why it is necessary to have EventId logged and it is not the same life without him – especially in the microservices context.

So why it is not enough

public static void LogError (this Microsoft.Extensions.Logging.ILogger logger, Exception? exception, string? message, params object?[] args);

and I strongly recommend

public static void LogError (this Microsoft.Extensions.Logging.ILogger logger, Microsoft.Extensions.Logging.EventId eventId, string? message, params object?[] args);

?

  Let’s assume that you have something like a log aggregator , such as ElasticSearch

You want to see from the error message , at a glace the details of the problem – like the root cause , some additional data – without going into details of the object. Something like “Drive C:  too full to write”  or “Drive D:  too full to write”  .

Also, you want to see how many error of this kind occurs – how many “ too full to write “ have occured ?

You ca put the message like “ Drive too full to write – look into details ” – and count those – but the investigators will have to click on more time to find what drive it is.

Welcome to EventID – https://docs.microsoft.com/en-us/dotnet/api/microsoft.extensions.logging.eventid?view=dotnet-plat-ext-6.0 .

You can have a

var evt = new EventId(7000,”DriveTooFull” );

logger.LogError(evt, “Drive C: too full to write” )

Now you have the message detaisl and you can count how many 7000 ( or DriveTooFull ) errors you have