mirror of
https://github.com/collinbarrett/FilterLists.git
synced 2026-03-11 09:04:27 +00:00
Revert "fix(logging): 🐛 rollback logging to previous working state"
This reverts commit 8126a489ac.
This commit is contained in:
parent
8126a489ac
commit
9edd95d3eb
4 changed files with 18 additions and 22 deletions
|
|
@ -1,5 +1,4 @@
|
|||
using Microsoft.ApplicationInsights;
|
||||
using Serilog;
|
||||
using Serilog;
|
||||
using Serilog.Events;
|
||||
|
||||
namespace FilterLists.SharedKernel.Logging
|
||||
|
|
@ -13,12 +12,5 @@ internal static class ConfigurationBuilder
|
|||
.MinimumLevel.Override("Microsoft.AspNetCore", LogEventLevel.Warning)
|
||||
.Enrich.FromLogContext()
|
||||
.WriteTo.Console();
|
||||
|
||||
public static LoggerConfiguration WriteToApplicationInsights(
|
||||
this LoggerConfiguration loggerConfiguration,
|
||||
TelemetryClient telemetryClient)
|
||||
{
|
||||
return loggerConfiguration.WriteTo.ApplicationInsights(telemetryClient, TelemetryConverter.Traces);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -21,13 +21,13 @@ public static void AddSharedKernelLogging(this IServiceCollection services, ICon
|
|||
{
|
||||
_ = configuration ?? throw new ArgumentNullException(nameof(configuration));
|
||||
|
||||
using var serverTelemetryChannel = new ServerTelemetryChannel
|
||||
{
|
||||
StorageFolder = configuration.GetSection(ApplicationInsightsOptions.Key)
|
||||
.Get<ApplicationInsightsOptions>()
|
||||
.ServerTelemetryChannelStoragePath
|
||||
};
|
||||
services.AddSingleton(typeof(ITelemetryChannel), serverTelemetryChannel);
|
||||
//using var serverTelemetryChannel = new ServerTelemetryChannel
|
||||
//{
|
||||
// StorageFolder = configuration.GetSection(ApplicationInsightsOptions.Key)
|
||||
// .Get<ApplicationInsightsOptions>()
|
||||
// .ServerTelemetryChannelStoragePath
|
||||
//};
|
||||
//services.AddSingleton(typeof(ITelemetryChannel), serverTelemetryChannel);
|
||||
services.AddApplicationInsightsTelemetry();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -17,11 +17,12 @@
|
|||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.ApplicationInsights.AspNetCore" Version="2.14.0" />
|
||||
<PackageReference Include="Microsoft.ApplicationInsights.AspNetCore" Version="2.13.1" />
|
||||
<PackageReference Include="Microsoft.CodeAnalysis.FxCopAnalyzers" Version="3.3.0">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="Microsoft.Extensions.Hosting.Abstractions" Version="3.1.8" />
|
||||
<PackageReference Include="Serilog.AspNetCore" Version="3.4.0" />
|
||||
<PackageReference Include="Serilog.Sinks.ApplicationInsights" Version="3.1.0" />
|
||||
</ItemGroup>
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.ApplicationInsights;
|
||||
using Microsoft.ApplicationInsights.Extensibility;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Hosting;
|
||||
using Serilog;
|
||||
|
||||
|
|
@ -8,13 +9,16 @@ namespace FilterLists.SharedKernel.Logging
|
|||
{
|
||||
public static class HostRunner
|
||||
{
|
||||
public static async Task<int> TryRunWithLoggingAsync(this IHost host, Func<Task>? runPreHostAsync = default)
|
||||
public static async Task TryRunWithLoggingAsync(this IHost host, Func<Task>? runPreHostAsync = default)
|
||||
{
|
||||
_ = host ?? throw new ArgumentNullException(nameof(host));
|
||||
|
||||
var telemetryClient = (TelemetryClient)host.Services.GetService(typeof(TelemetryClient));
|
||||
Log.Logger = ConfigurationBuilder.BaseLoggerConfiguration
|
||||
.WriteToApplicationInsights(telemetryClient)
|
||||
.WriteTo.Conditional(
|
||||
_ => host.Services.GetService<IHostEnvironment>().IsProduction(),
|
||||
c => c.ApplicationInsights(
|
||||
host.Services.GetRequiredService<TelemetryConfiguration>(),
|
||||
TelemetryConverter.Traces))
|
||||
.CreateLogger();
|
||||
|
||||
try
|
||||
|
|
@ -27,7 +31,6 @@ public static async Task<int> TryRunWithLoggingAsync(this IHost host, Func<Task>
|
|||
|
||||
Log.Information("Initializing host");
|
||||
await host.RunAsync();
|
||||
return 0;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
|
|
|
|||
Loading…
Reference in a new issue