To log or not to log
Found this gem.
protected void WriteEventLogError(string message)
{
if(_logger != null && string.IsNullOrEmty(message))
{
_logger.LogError(string.Format("{0} - {1}", this.Name, message));
}
}
Code block above doesn't log empty strings but why? What's bad about logging empty string if client calls it with such parameter?
In addition to hide the possible bug in logger's client, this code contains the bug by itself, effectively preventing errors to be logged.
One collegue of mine had a habbit to challenge the team with this question if we can't agree on something: What problem are we trying to solve?
I think every piece of code deserves at least little thought on why we need it in first place.
08/18/2023