2.1) Middleware جدید
- فایل: MIddlewares/XRequestLoggingMiddleware.cs (NEW)
- ویژگی: Simple/Full logging modes
- قابلیت: HTTP request/response logging، exception handling
⚠️ توجه: نام پوشه "MIddlewares" typo است - باید تصحیح شود
2.2) توسعه DI
- متد: AddXTelemetryLogger() - logging configuration
- متد: AddXTelemetry() - host builder extension
- متد: UseXRequestLogger() - middleware registration
2.3) بهروزرسانی Dependencies
- OpenTelemetry.Extensions.Hosting v1.6.0
- OpenTelemetry.Instrumentation.Http v1.6.0
- OpenTelemetry.Instrumentation.AspNetCore v1.6.0
- OpenTelemetry.Exporter.OpenTelemetryProtocol v1.6.0
- Microsoft.Extensions.Logging.Console v5.0.0
This commit is contained in:
@@ -1,12 +1,18 @@
|
||||
using System;
|
||||
using OpenTelemetry.Logs;
|
||||
using OpenTelemetry.Trace;
|
||||
using xCommons.Extensions;
|
||||
using xExceptions.Constants;
|
||||
using OpenTelemetry.Resources;
|
||||
using xLoggingService.Writers;
|
||||
using xEventService.Interfaces;
|
||||
using xLoggingService.Providers;
|
||||
using xLoggingService.Constants;
|
||||
using xLoggingService.Interfaces;
|
||||
using xLoggingService.MIddlewares;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Microsoft.Extensions.Hosting;
|
||||
using Microsoft.AspNetCore.Builder;
|
||||
using xLoggingService.Configuration;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
@@ -84,7 +90,7 @@ namespace xLoggingService.DI
|
||||
/// <param name="source"></param>
|
||||
/// <param name="configuration"></param>
|
||||
public static void AddXLoggingService(
|
||||
this IServiceCollection source,
|
||||
this IServiceCollection source,
|
||||
IConfiguration configuration
|
||||
)
|
||||
{
|
||||
@@ -96,6 +102,78 @@ namespace xLoggingService.DI
|
||||
);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Enable Telemetry Service on Logging ...
|
||||
/// </summary>
|
||||
/// <param name="builder"></param>
|
||||
public static void AddXTelemetryLogger(
|
||||
this ILoggingBuilder builder
|
||||
)
|
||||
{
|
||||
//
|
||||
AppContext.SetSwitch(
|
||||
"System.Net.Http.SocketsHttpHandler.Http2UnencryptedSupport", true);
|
||||
|
||||
//
|
||||
// Clear Providers ...
|
||||
builder.ClearProviders();
|
||||
builder.AddConsole();
|
||||
builder.AddOpenTelemetry(options =>
|
||||
{
|
||||
//
|
||||
options.SetResourceBuilder(
|
||||
ResourceBuilder
|
||||
.CreateDefault()
|
||||
.AddService(nameof(xLoggingService)));
|
||||
|
||||
//
|
||||
options.AddOtlpExporter();
|
||||
});
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Add Telemetry Service to Services ...
|
||||
/// </summary>
|
||||
/// <param name="builder"></param>
|
||||
/// <returns></returns>
|
||||
public static IHostBuilder AddXTelemetry(
|
||||
this IHostBuilder builder
|
||||
)
|
||||
{
|
||||
//
|
||||
// Configure Services ...
|
||||
builder = builder
|
||||
.ConfigureServices((hostContext, services) =>
|
||||
{
|
||||
//
|
||||
services
|
||||
.AddOpenTelemetry()
|
||||
.ConfigureResource(resource =>
|
||||
resource.AddService(nameof(xLoggingService)))
|
||||
.WithTracing(tracing =>
|
||||
tracing
|
||||
.AddAspNetCoreInstrumentation()
|
||||
.AddHttpClientInstrumentation()
|
||||
.AddOtlpExporter());
|
||||
});
|
||||
|
||||
//
|
||||
return builder;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Use Request Logging Middleware ...
|
||||
/// Log all Requests, and it's Flow to Logger ...
|
||||
/// </summary>
|
||||
/// <param name="source"></param>
|
||||
/// <returns></returns>
|
||||
public static IApplicationBuilder UseXRequestLogger(
|
||||
this IApplicationBuilder source
|
||||
)
|
||||
{
|
||||
return source.UseMiddleware<XRequestLoggingMiddleware>();
|
||||
}
|
||||
|
||||
//
|
||||
#region Private
|
||||
/// <summary>
|
||||
@@ -147,7 +225,7 @@ namespace xLoggingService.DI
|
||||
|
||||
//
|
||||
Log("FileLogWriter registered.");
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// Database Log Provider ...
|
||||
@@ -156,11 +234,11 @@ namespace xLoggingService.DI
|
||||
//
|
||||
services.TryAddEnumerable(
|
||||
ServiceDescriptor.Singleton<IXLogWriter, XDatabaseLogWriter>());
|
||||
|
||||
|
||||
//
|
||||
Log("DatabaseLogWriter registered.");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//
|
||||
// Event Service Provider ...
|
||||
if (configuration.Event.Enabled)
|
||||
@@ -177,7 +255,7 @@ namespace xLoggingService.DI
|
||||
//
|
||||
services.TryAddEnumerable(
|
||||
ServiceDescriptor.Singleton<IXLogWriter, XEventLogWriter>());
|
||||
|
||||
|
||||
//
|
||||
Log("EventLogWriter registered.");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user