mirror of
https://github.com/collinbarrett/FilterLists.git
synced 2026-03-11 09:04:27 +00:00
Revert "fix(logging): 🐛 try fully inline initialization to fix AppInsights"
This reverts commit 5bff4c3229.
This commit is contained in:
parent
0bae0a21e0
commit
a0b0b63d69
2 changed files with 10 additions and 13 deletions
|
|
@ -1,14 +1,12 @@
|
|||
using System;
|
||||
using FilterLists.SharedKernel.Logging.Options;
|
||||
using Microsoft.ApplicationInsights.Channel;
|
||||
using Microsoft.ApplicationInsights.Extensibility;
|
||||
using Microsoft.ApplicationInsights.WindowsServer.TelemetryChannel;
|
||||
using Microsoft.AspNetCore.Builder;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Hosting;
|
||||
using Serilog;
|
||||
using Serilog.Events;
|
||||
|
||||
namespace FilterLists.SharedKernel.Logging
|
||||
{
|
||||
|
|
@ -16,17 +14,7 @@ public static class ConfigurationExtensions
|
|||
{
|
||||
public static IHostBuilder UseLogging(this IHostBuilder hostBuilder)
|
||||
{
|
||||
return hostBuilder.UseSerilog((_, services, lc) =>
|
||||
lc.MinimumLevel.Debug()
|
||||
.MinimumLevel.Override("Microsoft", LogEventLevel.Information)
|
||||
.MinimumLevel.Override("Microsoft.AspNetCore", LogEventLevel.Warning)
|
||||
.Enrich.FromLogContext()
|
||||
.WriteTo.Console()
|
||||
.WriteTo.Conditional(
|
||||
__ => services.GetService<IHostEnvironment>().IsProduction(),
|
||||
sc => sc.ApplicationInsights(
|
||||
services.GetRequiredService<TelemetryConfiguration>(),
|
||||
TelemetryConverter.Traces)));
|
||||
return hostBuilder.UseSerilog();
|
||||
}
|
||||
|
||||
public static void AddSharedKernelLogging(this IServiceCollection services, IConfiguration configuration)
|
||||
|
|
|
|||
|
|
@ -1,5 +1,7 @@
|
|||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.ApplicationInsights;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Hosting;
|
||||
using Serilog;
|
||||
|
||||
|
|
@ -11,6 +13,13 @@ public static async Task TryRunWithLoggingAsync(this IHost host, Func<Task>? run
|
|||
{
|
||||
_ = host ?? throw new ArgumentNullException(nameof(host));
|
||||
|
||||
var telemetryClient = (TelemetryClient)host.Services.GetService(typeof(TelemetryClient));
|
||||
Log.Logger = ConfigurationBuilder.BaseLoggerConfiguration
|
||||
.WriteTo.Conditional(
|
||||
_ => host.Services.GetService<IHostEnvironment>().IsProduction(),
|
||||
c => c.ApplicationInsights(telemetryClient, TelemetryConverter.Traces))
|
||||
.CreateLogger();
|
||||
|
||||
try
|
||||
{
|
||||
if (runPreHostAsync != null)
|
||||
|
|
|
|||
Loading…
Reference in a new issue