I am currently using AWS.Logger.AspNetCore v3.0.1 as my logging system inside a .Net Core Web API project.
I've got my logging set up simply in Program.cs, like so:
.ConfigureLogging(logging =>
{
logging.AddAWSProvider();
}
with the log stream and flags set in appsettings.json. So far, so good.
I was wondering if anyone could possibly help with the following:
- I'd like to prepend text to all the messages logged - even before the log level, category, scope.
I know there is an overload of AddAWSProvider() which lets me supply my own custom message formatter which AWSLogger instance uses. I could add this to Program.cs for example:
[IHostBuilder].ConfigureLogging(logging =>
{
logging.AddAWSProvider(((level, state, exception) =>
{
// TODO: Add formatting code which returns a formatted log entry string here
}));
})
however this approach doesn't give me access to the "Scope" supplied to ILogger.BeginScope() which I need to see my connection ID, trace ID etc.
Any ideas on how I can intercept the full string (not just the message!) to be sent to AWS and then transform it? I don't have a lot of time left to spend on this, so switching to something like Log4Net, Serilog or creating a full LogProvider or ScopeProvider is not an option.
Even something that auto-prefixes a custom formatted TimeStamp would be satisfactory. (And yes, I know AWS CloudWatch logs display a timestamp, but not when you "View As Text" )
- Are there any docs on the AWSLoggerCore daemon? (AWS.Logger.Core.AWSLoggerCore::StartMonitor() and Monitor() )
I've looked at the code and noticed it dispatches to AWS a max of 5 requests (log messages) per second. However, I don't know how regularly it checks for new messages, and whether we can control that to ensure messages are logged immediately. Nor do I know how often or under what circumstances it calls Flush(). Losing vital log messages could prevent us tracing future issues.
The API runs within an EC2 container.
Thanks in advance,
Scott
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…