public HostBuilderLoggerEmitterService(IHostApplicationLifetime appLife, ILoggerFactory logFactory) { var logger = logFactory.CreateLogger(nameof(HostBuilderLogger)); appLife.ApplicationStarted.Register(() => { logger.LogInformation(HostBuilderLoggerMessage.FormattedMessage("Application started normally.\nEmitting messages cached during HostBuilder configuration.")); HostBuilderLogger.Logger.EmitCachedMessages(logger); }); }
public HostBuilderLoggerTerminatorService(IHostApplicationLifetime appLife, ILoggerFactory logFactory) { var logger = logFactory.CreateLogger(nameof(HostBuilderLogger)); appLife.ApplicationStarted.Register(() => { logger.LogWarning(HostBuilderLoggerMessage.FormattedMessage("Abnormal application shutdown.\nEmitting messages cached during HostBuilder configuration.")); HostBuilderLogger.Logger.EmitCachedMessages(logger); appLife.StopApplication(); }); }