Serilog extension for the exception handling
using PackZero.Logging;
exception format is {logType}: {Message} {StackTrace} {Source} {InnerMessage} {InnerStackTrace} {InnerSource} {ExceptionNote}
public class AppHostedService : IHostedService
{
private readonly ILogger<AppHostedService> logger;
public AppHostedService(ILogger<AppHostedService> logger)
{
this.logger = logger;
}
public async Task StartAsync(CancellationToken cancellationToken)
{
try
{
//actions
}
catch (Exception e)
{
logger.Exception(e);
}
}
}
- IHostBuilder extension named
UseAppZeroLogging()
extendsConfigureLogging()
and overrides Serilog LoggerConfiguration using internallyUseSerilog()
- Application Name and Environment information will be added as property on Serilo