How to use Microsoft. Extensions. Logging in WPF (.net 9.0) ?

929Free 641 Reputation points
2025-05-25T18:04:55.7066667+00:00

I have been searching for information online for a long time, but have not found the latest correct usage method. Can you please help me? thanks

Developer technologies Windows Presentation Foundation
0 comments No comments
{count} votes

Accepted answer
  1. S.Sengupta 24,476 Reputation points MVP
    2025-05-26T01:58:33.9466667+00:00
    • Install NuGet packages:

    dotnet add package Microsoft.Extensions.Logging

    dotnet add package Microsoft.Extensions.Logging.Console

    Microsoft.Extensions.DependencyInjection

    Ref:

    https://www.nuget.org/packages/Microsoft.Extensions.Logging/

    • Configure logging in App.xaml.cs using ServiceCollection and dependency injection
    • Inject ILogger<T> into ViewModels and code-behind classes
    • Output

    https://learn.microsoft.com/en-us/dotnet/core/extensions/logging?tabs=command-line

    1 person found this answer helpful.
    0 comments No comments

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.