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!
question from:
https://stackoverflow.com/questions/65948566/aws-cloudwatch-how-to-remove-loglevel-and-class-that-logged-in-default-for-ne 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…