MappingGenerator Premium provides a set of scaffoldings that facilitate the usage of Microsoft.Extensions.Logging.ILogger
.
This premium code action automatically injects a strongly typed logger. It works as follows:
Microsoft.Extensions.Logging
namespace if necessary.ILogger<T>
private, readonly field if necessary.ILogger<T>
instance through the existing constructors or adds a new constructor if necessary.Automatically inject logger (if needed) and log text with the desired severity.
This premium code action works in a similar way as Add logger
but additionally insert invocation of LogError
method with exception from the current scope. If catch
section is missing, then code action adds it automatically:
Wrap the selected code block with try..catch
statement, automatically inject the logger (if needed) and log the caught exception.
Wrap the selected code block with using
statement for ILogger.BeginScope
. If there’s no field with logger, then inject it automatically.