From 38b945e3d29233a46bd5107638c4581b07edcbef Mon Sep 17 00:00:00 2001 From: akondratov <22258361+andrey-kondratov@users.noreply.github.com> Date: Thu, 15 Aug 2024 23:34:11 +0300 Subject: [PATCH] Fixed AI log level configuration. --- .../Configuration/ServiceCollectionExtensions.cs | 6 +++++- src/PillsBot/PillsBot.Server/Program.cs | 2 ++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/PillsBot/PillsBot.Server/Configuration/ServiceCollectionExtensions.cs b/src/PillsBot/PillsBot.Server/Configuration/ServiceCollectionExtensions.cs index 268d10d..aa48b71 100644 --- a/src/PillsBot/PillsBot.Server/Configuration/ServiceCollectionExtensions.cs +++ b/src/PillsBot/PillsBot.Server/Configuration/ServiceCollectionExtensions.cs @@ -1,8 +1,10 @@ using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Logging; using Microsoft.Extensions.Options; using Microsoft.SemanticKernel.ChatCompletion; using Microsoft.SemanticKernel.Connectors.OpenAI; +using Serilog; namespace PillsBot.Server.Configuration { @@ -24,7 +26,9 @@ public static IServiceCollection AddPillsBot(this IServiceCollection services, I { AIOptions.AzureOpenAIOptions options = provider.GetRequiredService>().Value.AI.Azure; - return new AzureOpenAIChatCompletionService(options.DeploymentName, options.Endpoint, options.Key); + return new AzureOpenAIChatCompletionService(options.DeploymentName, options.Endpoint, options.Key, + loggerFactory: new LoggerFactory() + .AddSerilog(provider.GetRequiredService())); }) .AddSingleton() .AddTransient() diff --git a/src/PillsBot/PillsBot.Server/Program.cs b/src/PillsBot/PillsBot.Server/Program.cs index 8264b31..37985c3 100644 --- a/src/PillsBot/PillsBot.Server/Program.cs +++ b/src/PillsBot/PillsBot.Server/Program.cs @@ -2,6 +2,7 @@ using Microsoft.ApplicationInsights.Extensibility; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Hosting; +using Microsoft.Extensions.Options; using PillsBot.Server.Configuration; using Serilog; using Serilog.Events; @@ -39,6 +40,7 @@ public static IHostBuilder CreateHostBuilder(string[] args) => Host .AddPillsBot(context.Configuration.GetSection("PillsBot"))) .UseSerilog((context, services, configuration) => configuration .MinimumLevel.Is(context.HostingEnvironment.IsDevelopment() ? LogEventLevel.Debug : LogEventLevel.Information) + .MinimumLevel.Override("Microsoft.SemanticKernel", (LogEventLevel) services.GetRequiredService>().Value.AI.LogLevel) .Enrich.FromLogContext() .Enrich.WithProperty("Environment", context.HostingEnvironment.EnvironmentName) .Enrich.WithProperty("Version", typeof(Program).Assembly.GetName().Version.ToString(3), true)