public LoggerFactory(EnvironmentNameSetting environmentName, EnvironmentTypeSetting environmentType, MinimumLogLevelSetting minimumLogLevel, SeqServerUriSetting seqServerUri) { _environmentName = environmentName; _environmentType = environmentType; _minimumLogLevel = minimumLogLevel; _seqServerUri = seqServerUri; }
public static IApplicationBuilder UseCustomExceptionHandling( this IApplicationBuilder applicationBuilder, EnvironmentTypeSetting environmentType) => environmentType.IsLocal() ? applicationBuilder .UseDeveloperExceptionPage() : applicationBuilder .UseExceptionHandler("/error") .UseStatusCodePagesWithReExecute("/error/{0}");
public static LoggerConfiguration SetupCustomLogger(this LoggerConfiguration loggerConfiguration, Assembly assembly, EnvironmentTypeSetting environmentType, SeqServerUriSetting seqServerUri, SeqServerApiKeySetting seqServerApiKey) { var assemblyName = assembly.GetName().Name; var infoVerAttr = (AssemblyInformationalVersionAttribute)assembly .GetCustomAttributes(typeof(AssemblyInformationalVersionAttribute)).FirstOrDefault(); var assemblyVersion = infoVerAttr?.InformationalVersion; var levelSwitch = new LoggingLevelSwitch(LogEventLevel.Verbose); loggerConfiguration .MinimumLevel.ControlledBy(levelSwitch) .If(environmentType.IsProduction(), _ => _.MinimumLevel.Override("Microsoft", LogEventLevel.Warning)) .If(environmentType.IsProduction(), _ => _.MinimumLevel.Override("System", LogEventLevel.Warning)) .If(environmentType.IsProduction(), _ => _.MinimumLevel.Override("Microsoft.EntityFrameworkCore.Database.Command", LogEventLevel.Information)) // Log SQL Queries from EF .Destructure.ToMaximumDepth(4) .Destructure.ToMaximumCollectionCount(10) .Enrich.FromLogContext() .Enrich.WithMachineName() .Enrich.WithThreadId() .Enrich.WithProcessId() .Enrich.WithExceptionDetails() .Enrich.WithCorrelationIdHeader() .Enrich.WithProperty("ApplicationName", assemblyName) .Enrich.WithProperty("ApplicationVersion", assemblyVersion) .Enrich.WithProperty("EnvironmentType", environmentType.Value.ToString()) .If(!environmentType.IsProduction(), loggerConfiguration => loggerConfiguration.WriteTo.Console() ) .WriteTo.Seq( seqServerUri.Value, apiKey: seqServerApiKey.Value, controlLevelSwitch: levelSwitch); return(loggerConfiguration); }
public static IApplicationBuilder UseCustomSwagger(this IApplicationBuilder applicationBuilder, EnvironmentTypeSetting environmentType) { if (environmentType.IsNonProduction()) { applicationBuilder.UseOpenApi().UseSwaggerUi3(); } return(applicationBuilder); }
public HandleAjaxExceptionsFilter(EnvironmentTypeSetting environmentType, ILogger logger) { _environmentType = environmentType; _logger = logger; }