I am using NLog in a .Net Core 2.2 project.
I want to implement a category system for my logs using EventId (supported in NLog).
Currently I am using the logger like this:
logger.LogInformation(new EventId(5, "UserLogin"), "The user: {username} logged in.", username);
logger.LogInformation(new EventId(6, "UserChangedPassword"), "The user: {username} changed their password.", username);
But I would much prefer to be able to use it like this:
logger.LogUserLogin(username);
logger.LogUserChangedPassword(username);
Where LogUserLogin and LogUserChangedPassword are custom functions that would add in the correct EventId id and name and then log the event as LogInformation.
My questions are:
- How can I extend the logger with my custom functions?
- Is this the wrong/non-ideal way to implement a category system for NLog? Should I rather define the EventId as I'm writing the logs, like I'm doing currently?
I feel like this should be relatively simple, but my googling skills seem to be failing me at the moment.