I've added NLog to my ASP.Net Core project and I'm about to sprinkle logging everywhere, but before I do, I wanted to get some advice on what I should be logging at the various log levels (Specifically debug and info).
I'll have 1 logger per class.
In my controllers, I think it makes sense to have a log.Debug() line at the beginning and end of each of the action, with details of all of the parameters and the result at the end of the action (Both of which can be achieved by an actionFilter).
So what should I be logging at the info level? (Assuming the debug level will be off until I need to debug a problem).
Should I be recording just that the action was called, with perhaps an additional log.info() at the end of the method if it was successful, without logging any parameters or results?
What about all of the methods the controller calls? I'd want to record the inputs and outputs of those at least at the debug level, so it probably make sense to put those within those methods, rather than outside the method (i.e. before and after it)? (I've seen that PostSharp Diagnostics could be a good fit for this-never used it before).
Is it common to also log at the info level within these methods at the start and end, and again, would it just be recording that it was called and a second log.info() to indicate that it's successfully completed, or is that too much detail for info?
What's the recommended approach regarding auditing?(Probably quite objective). The most appropriate logging level is probably info, but then it will get mixed in with your far more basic info logging. How would you sensibly separate the two (i.e. both logged at the same log level, but kept separate in the logs). I see that NLog has the ability to filter logs, so I suppose I could stick "Audit" at the front of every log.info() which pertains to auditing, but that seems a bit dirty.
Of course this is opinion based, but I follow these rules:
Is it common to also log at the info level within these methods at the start and end,
Only at trace level in my opinion.
For the other three levels we have the following rules:
What's the recommended approach regarding auditing?(Probably quite objective). The most appropriate logging level is probably info, but then it will get mixed in with your far more basic info logging. How would you sensibly separate the two (i.e. both logged at the same log level, but kept separate in the logs).
Create a separate logger and rules. E.g.
var auditingLogger = LogManager.GetLogger("auditing");
config:
<logger name="auditing" minlevel="Info" writeTo="auditing-file" />