【发布时间】:2021-08-23 16:46:24
【问题描述】:
我在 .NET Core 服务中使用来自 Microsoft.IdentityModel.S2S 命名空间的 S2SAuthenticationHandler 进行身份验证。
当身份验证失败时,有许多冗余错误日志我希望作为警告(例如,如果令牌已过期 - 我不希望看到任何错误)。
如果我将 minimum 日志级别设置为 Critical(以避免 Error 日志),我会错过一些有关身份验证失败原因的信息。
有没有办法将库的错误日志级别降低到警告?
谢谢!
services.AddAuthentication()
.AddS2SAuthentication(services, authManager, options =>
{
var events = new S2SAuthenticationEvents
{
OnTokenValidated = validatedToken =>
{
validatedToken.Principal = FixClaims(validatedToken.AuthenticationTicket);
return Task.FromResult<object>(null);
},
OnAuthenticationMessageReceived = context =>
{
context.S2SContext = new S2SContext(Guid.NewGuid()) { CaptureLogs = true };
return Task.FromResult<object>(null);
},
OnAuthenticationFailed = context =>
{
// This exception do not the authentication failure reason
logger.LogWarning(context.Exception, "Authentication failed, exception might contain additional details");
return Task.FromResult<object>(null);
}
};
options.Events = events;
})
【问题讨论】:
-
@SnowGroomer OP 正在谈论来自库的一些日志消息声明为错误,他会将它们归类为警告
标签: c# asp.net asp.net-core authentication .net-core