Ayobamilaye
Ayobamilaye

Reputation: 1573

ASP.NET Core Web API - How to resolve conflict between Serilog and Microsoft.Extensions.Logging

In my ASP.NET Core-6 Web API, I installed Serilog. I never installed Microsoft.Extensions.Logging

But to my surprise, when I wanted to reference Serilog using:

using ILogger = Serilog.ILogger;

public class AuthController : BaseApiController
{
    private readonly ILogger<AuthController> _logger;
    private IAuthService _authService;

    public AuthController(ILogger<AuthController> logger, IAuthService authService)
    {
        _logger = logger;
        _authService = authService;
    }
}

ILogger automatically detect Microsoft.Extensions.Logging, and I couldn't change to Serilog.

How do I resolve this?

Thanks

Upvotes: 3

Views: 895

Answers (1)

CER
CER

Reputation: 253

.NET 6 by default turns on "implicit usings" ( <ImplicitUsings>enable</ImplicitUsings>) in your .csproj file. ASP.NET Core 6 by default includes Microsoft.Extensions.Logging.

You can either 'disable' all "usings" or remove Microsoft.Extensions.Logging explicitly in your .csproj file.

<ItemGroup>
  <Using Remove="Microsoft.Extensions.Logging" />
</ItemGroup>

See here for more info.

Upvotes: 6

Related Questions