AWS CloudWatch - 如何删除默认登录 .NET Core 的 LogLevel 和 Class? [英] AWS CloudWatch - How to remove LogLevel and Class that logged in default for .NET Core?
问题描述
我已成功将 .NET Core API 中的消息记录到 AWS CloudWatch.
然而,我发现消息会自动包含LogLevel和打印日志的类,如下:
[信息] Infra.Logging:{id":001",消息":收到的获取数据请求",日志级别":信息";}
我想去掉[Information]
&Infra.Logging
来自消息.我尝试将 appsettings 配置如下:
记录":{IncludeLogLevel":假,包括类别":假,包括换行符":假,包括异常":假,IncludeEventId":假,包括范围":假,日志级别":{默认":跟踪",系统":信息",微软":信息"}}
但是它不起作用.有什么办法可以去掉CloudWatch中自动添加到@message
中的两个字段?
这是我记录消息的方式:
var loggerConfig = 新的 AWSLoggerConfig{日志组 = 日志组,地区 = 地区};var logFactory = new LoggerFactory();logFactory.AddAWSProvider(loggerConfig);var logger = logFactory.CreateLogger();logger.LogInformation(logMessageString);
logMessageString
将是从 JSON 转换的字符串:
<代码>{id":001",消息":收到的获取数据请求",日志级别":信息";}
我想删除的原因是因为我希望像这样查询我的Insight日志:
fields @timestamp, @message|过滤器 ID =001"|排序@timestamp desc
此查询现在不起作用,所以我认为可能是默认记录的 [Information]
&Infra.Logging
问题.
感谢任何帮助!
使用您现有的日志记录,即使用 [Information] Infra.Logging:
之后的进一步日志消息.您可以使用 parse
命令,如下所示.有关解析命令的更多详细信息,请参阅
一种可能的解决方案是按如下方式执行 aws cloud watchinsight 查询;
字段@message |解析@message '[*] Infra.Logging:{id":*"'作为@loggingType,@some_id |过滤@loggingType='Information' 和@some_id like '2' |排序@timestamp desc
执行aws cloud watch洞察查询后的输出如下;
I have success logged the message from my .NET Core API to AWS CloudWatch.
However, I found that the message will automatically consist LogLevel and the class that prints the logs, as below:
[Information] Infra.Logging:
{
"id": "001",
"message": "Received Get Data Request",
"logLevel": "Information"
}
I want to get rid of the [Information]
& Infra.Logging
from the message. I tried to configure the appsettings as below:
"Logging": {
"IncludeLogLevel": false,
"IncludeCategory": false,
"IncludeNewline": false,
"IncludeException": false,
"IncludeEventId": false,
"IncludeScopes": false,
"LogLevel": {
"Default": "Trace",
"System": "Information",
"Microsoft": "Information"
}
}
But it is not working. Is there any way that can remove the two field that's added automatically into @message
in the CloudWatch?
Here is how I logged the message:
var loggerConfig = new AWSLoggerConfig
{
LogGroup = logGroup,
Region = region
};
var logFactory = new LoggerFactory();
logFactory.AddAWSProvider(loggerConfig);
var logger = logFactory.CreateLogger<Infra.Logging>();
logger.LogInformation(logMessageString);
The logMessageString
will be the string convert from JSON:
{
"id": "001",
"message": "Received Get Data Request",
"logLevel": "Information"
}
The reason I want to remove is because I wish to query my log in Insight like:
fields @timestamp, @message
| filter id="001"
| sort @timestamp desc
This query is not working now so I figured might be the default logged [Information]
& Infra.Logging
issue.
Appreciates any helps!
With your existing logging i.e. with [Information] Infra.Logging:
after that the further log message.
You can use parse
command as shown below. For more details about parse command, please refer this document from AWS.
Assumption: You have following logging structure;
One of possible solution is to execute aws cloud watch insight query as follows;
fields @message | parse @message '[*] Infra.Logging: {"id": "*"' as @loggingType, @some_id | filter @loggingType='Information' and @some_id like '2' | sort @timestamp desc
Output after execution aws cloud watch insight query is as follows;
这篇关于AWS CloudWatch - 如何删除默认登录 .NET Core 的 LogLevel 和 Class?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!