• Что бы вступить в ряды "Принятый кодер" Вам нужно:
    Написать 10 полезных сообщений или тем и Получить 10 симпатий.
    Для того кто не хочет терять время,может пожертвовать средства для поддержки сервеса, и вступить в ряды VIP на месяц, дополнительная информация в лс.

  • Пользаватели которые будут спамить, уходят в бан без предупреждения. Спам сообщения определяется администрацией и модератором.

  • Гость, Что бы Вы хотели увидеть на нашем Форуме? Изложить свои идеи и пожелания по улучшению форума Вы можете поделиться с нами здесь. ----> Перейдите сюда
  • Все пользователи не прошедшие проверку электронной почты будут заблокированы. Все вопросы с разблокировкой обращайтесь по адресу электронной почте : info@guardianelinks.com . Не пришло сообщение о проверке или о сбросе также сообщите нам.

Fix Semantic Kernel logging when using Dependency Injection

Lomanu4 Оффлайн

Lomanu4

Команда форума
Администратор
Регистрация
1 Мар 2015
Сообщения
1,481
Баллы
155
Integrating Semantic Kernel into ASP.NET applications is straightforward, due to built-in support for Dependency Injection (DI). This makes well-known features such as configuration, logging, and hosting trivial to use for AI Agent development. However, while debugging an agent issue, I discovered that all logging information from the Semantic Kernel was missing! This article explains issue's root cause and how to fix it.

The Original Setup


Here is a simplified version of the code I used to set up and use the Semantic Kernel in my ASP.NET application. Please note how IChatCompletionService and Kernel services are registered within DI container.


We use Agent to complete a chat based on user's prompt. All dependencies are injected into the Agent constructor automatically.

The Problem


After detecting an unrelated issue in request processing, I turned to good old console logs to find the root cause. To my surprise, I noticed no logging information was generated by the Kernel.


Пожалуйста Авторизируйтесь или Зарегистрируйтесь для просмотра скрытого текста.



At first, I thought it was a configuration issue. But no matter how I configured the logging, nor what scope I set, the Kernel information was missing from the console. I even tried to set the logging level to Debug or Verbose, but nothing worked.

The Solution


It turned out that the issue was not in the Kernel itself, but in the way how underlying AzureOpenAIChatCompletionService was created. Even though the _kernel instance was used to call GetChatMessageContentAsync() method of IChatCompletionService, logging provider registered in DI container was not used. The solution was to provide it during registration of the AzureOpenAIChatCompletionService instance.


And whoila! Now we can see the debug information in the console!


Пожалуйста Авторизируйтесь или Зарегистрируйтесь для просмотра скрытого текста.



Conclusion


Even though the Semantic Kernel is designed to work with DI, it does not mean other parts of .NET AI stack are. However, in this case, the solution was simple. Just make sure to pass the logging factory to the IChatCompletionService implementation.


Пожалуйста Авторизируйтесь или Зарегистрируйтесь для просмотра скрытого текста.

 
Вверх Снизу