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
CodePudding user response:
.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.