From 374c3258efb7e6550fe8b79967e6cdc29094ee51 Mon Sep 17 00:00:00 2001 From: Hadi Khazaee Asl Date: Mon, 9 Nov 2026 12:53:05 +0330 Subject: [PATCH] - .gitignore: +Logs - Program.cs: Telemetry configuration - Startup.cs: Request logging middleware --- Program.cs | 22 ++++++++++++++++------ Startup.cs | 10 +++++++++- xApi.csproj | 19 +++++++++++++++---- 3 files changed, 40 insertions(+), 11 deletions(-) diff --git a/Program.cs b/Program.cs index 63cc5ec..e1c7b03 100644 --- a/Program.cs +++ b/Program.cs @@ -1,3 +1,4 @@ +using xLoggingService.DI; using Microsoft.AspNetCore.Hosting; using Microsoft.Extensions.Hosting; @@ -10,11 +11,20 @@ namespace xApi CreateHostBuilder(args).Build().Run(); } - public static IHostBuilder CreateHostBuilder(string[] args) => - Host.CreateDefaultBuilder(args) - .ConfigureWebHostDefaults(webBuilder => - { - webBuilder.UseStartup(); - }); + public static IHostBuilder CreateHostBuilder(string[] args) + { + // + var result = Host.CreateDefaultBuilder(args) + .ConfigureLogging(logging => + logging.AddXTelemetryLogger()) + .ConfigureWebHostDefaults(webBuilder => + { + webBuilder.UseStartup(); + }) + .AddXTelemetry(); + + // + return result; + } } } \ No newline at end of file diff --git a/Startup.cs b/Startup.cs index 1c5ea71..2077d82 100644 --- a/Startup.cs +++ b/Startup.cs @@ -130,7 +130,8 @@ namespace xApi ) { // - if (env.IsDevelopment()) + var isDevelopmentEnvironment = env.IsDevelopment(); + if (isDevelopmentEnvironment) { app.UseDeveloperExceptionPage(); } @@ -153,6 +154,13 @@ namespace xApi // app.UseRouting(); + // + // Using Request Logging ... + if (!isDevelopmentEnvironment) + { + app.UseXRequestLogger(); + } + // // Enable Api Key Usage Logs ... // app.UseXApiKeyUsage(); diff --git a/xApi.csproj b/xApi.csproj index 3b12c92..e76fd79 100644 --- a/xApi.csproj +++ b/xApi.csproj @@ -1,4 +1,5 @@ + 1.0.0 @@ -7,37 +8,48 @@ xSaherElm.xApi SaherElm IT Center netcoreapp3.1 + a WebAPI Project which contains all Business Logic of xSaherElm Project. + icon.png + false false + + + + + - + + + $(NoWarn);1591 true true + @@ -45,11 +57,10 @@ all + - - - + \ No newline at end of file