Disable log in custom AuthenticationHandler
See original GitHub issueIs there an existing issue for this?
- I have searched the existing issues
Is your feature request related to a problem? Please describe the problem.
No response
Describe the solution you’d like
I can’t disable log by using
"Logging": { "LogLevel": { "Microsoft.AspNetCore.Authentication": "Warning" } }
in appsettings.json, but if I set logging level for a custom AuthenticationHandler. It will disable all other logs that I provided.
I just want to disable the logs from “Microsoft.AspNetCore.Authentication”, the parent class.
Using “Microsoft.AspNetCore.Authentication”: “Warning” to change log level only for the parent class.
Additional context
No response
Issue Analytics
- State:
- Created a year ago
- Comments:9 (7 by maintainers)
Top Results From Across the Web
How to turn off the logging done by the ASP.NET core ...
Since your logger provider is a custom one, you will have to configure it yourself. Take a look on how the console logger...
Read more >Working with custom authentication schemes in ASP.NET ...
The authentication handler in its most basic form only implements the HandleAuthenticateAsync method, by overriding it.
Read more >Overview of ASP.NET Core Authentication
To disable automatically using the single authentication scheme as the DefaultScheme , call AppContext.SetSwitch("Microsoft.AspNetCore.
Read more >Authorize with a specific scheme in ASP.NET Core
This article explains how to limit identity to a specific scheme when working with multiple authentication methods.
Read more >Authentication Handler in AEM: custom approach
If we want to avoid that we can disable the anonymous access to it via Apache Sling Authentication Service. We can also filter...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@Tratcher Could you please explain how it will work because the logs from the Base and Derived will have the same logger category name? Look at the code:
The logs:
We need to know how to disable logs from the
AuthenticationHandler
class (AuthenticationScheme: MyAuthenticationScheme was challenged.).Should we then create something like this in MyAuthenticationHandler :
The logs:
then filter all logs for
DummyMyAuthenticationHandler
to hide “AuthenticationScheme: MyAuthenticationScheme was challenged.”?after this the logs:
It looks strange!
It would be better to change this https://github.com/dotnet/aspnetcore/blob/34f71bb22ce65e59c9b9bfbe3e183db395ef5595/src/Security/Authentication/Core/src/AuthenticationHandler.cs#L112 to
Logger = logger.CreateLogger<AuthenticationHandler>();
Then the log will be:
So, just add
after this the logs will be expected:
You’d need to give your logger in the derived class a different category name so you can configure it independently from the base class.