使用Serilog在Azure上使用Serilog的过滤身份验证消息
我需要使用 Serilog 在 Azure 上过滤以下消息: AuthenticationScheme:BasicAuthentication 已成功验证。 该消息为信息级别。
在下面的代码中,我输入了到目前为止我尝试过的所有内容,并且仍然收到这些日志。 我在 asp.net 项目中使用 .net 6。
public static void Configure(WebApplicationBuilder builder)
{
if(builder is null)
return;
Log.Logger = new LoggerConfiguration()
.Enrich.FromLogContext()
.Enrich.WithProcessId()
.Enrich.WithProcessName()
.Enrich.WithThreadId()
.MinimumLevel.Override("Microsoft.EntityFrameworkCore.Database.Command", LogEventLevel.Warning)
.MinimumLevel.Override("Microsoft", LogEventLevel.Information)
.MinimumLevel.Override("Microsoft.AspNetCore", LogEventLevel.Warning)
.MinimumLevel.Debug()
.WriteTo.Async(x => x.Logger((configureLogger) =>
{
configureLogger.Filter.ByExcluding(logEvent =>
logEvent.MessageTemplate.Text.ToLower().Contains("authenticationscheme: basicauthentication") &&
logEvent.Level < LogEventLevel.Warning);
configureLogger.WriteTo.Async(consoleConfiguration =>
{
consoleConfiguration.Console(new ExpressionTemplate(
template: "{@l:w4}: {SourceContext}\n" +
"{#if Scope is not null}" +
"\t{#each s in Scope}=> - {s}{#delimit} {#end}\n" +
"{#end}" +
"{@m}\n",
theme: TemplateTheme.Code));
});
}))
.CreateBootstrapLogger();
builder.WebHost.UseSerilog();
}
在本地,这很完美。当我记录如下信息时:
logger.LogInformation("AuthenticationScheme: BasicAuthentication".ToUpper());
过滤器应用于本地,但不在 Azure 上。 有什么想法吗? 谢谢
I need to filter the following message on Azure using Serilog:
AuthenticationScheme: BasicAuthentication was successfully authenticated. The message is Information level.
In the below code I put everything I tried so far, and am still getting those logs.
I am using .net 6 in asp.net project.
public static void Configure(WebApplicationBuilder builder)
{
if(builder is null)
return;
Log.Logger = new LoggerConfiguration()
.Enrich.FromLogContext()
.Enrich.WithProcessId()
.Enrich.WithProcessName()
.Enrich.WithThreadId()
.MinimumLevel.Override("Microsoft.EntityFrameworkCore.Database.Command", LogEventLevel.Warning)
.MinimumLevel.Override("Microsoft", LogEventLevel.Information)
.MinimumLevel.Override("Microsoft.AspNetCore", LogEventLevel.Warning)
.MinimumLevel.Debug()
.WriteTo.Async(x => x.Logger((configureLogger) =>
{
configureLogger.Filter.ByExcluding(logEvent =>
logEvent.MessageTemplate.Text.ToLower().Contains("authenticationscheme: basicauthentication") &&
logEvent.Level < LogEventLevel.Warning);
configureLogger.WriteTo.Async(consoleConfiguration =>
{
consoleConfiguration.Console(new ExpressionTemplate(
template: "{@l:w4}: {SourceContext}\n" +
"{#if Scope is not null}" +
"\t{#each s in Scope}=> - {s}{#delimit} {#end}\n" +
"{#end}" +
"{@m}\n",
theme: TemplateTheme.Code));
});
}))
.CreateBootstrapLogger();
builder.WebHost.UseSerilog();
}
In local this works perfect. When the I log an information like this:
logger.LogInformation("AuthenticationScheme: BasicAuthentication".ToUpper());
the filter is applied in local, but not on Azure.
Any idea?
thnx
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
使用 serilog.expressions :
Using Serilog.Expressions: