I have used Serilog in the past and enriched logs with various properties. However I am playing around with the new AWS Lambda Serverless templates using .net core 3.1 and cannot get the logs to enrich. I have tried this in a basic Console app as well with the same result.
Example: code:
class Program
{
static void Main(string[] args)
{
Log.Logger = new LoggerConfiguration()
.MinimumLevel.Debug()
.WriteTo.AWSSeriLog(GetAwsSerilogConfiguration())
.Enrich.FromLogContext()
.Enrich.WithMachineName()
.CreateLogger();
using (LogContext.PushProperty("A", 1))
{
Log.Information("Starting web host");
Console.WriteLine("Hello World!");
}
}
private static AWSLoggerConfig GetAwsSerilogConfiguration()
{
var environmentName = Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT");
return new AWSLoggerConfig
{
LogGroup = $"AwsLoggingTestConsoleApp/{environmentName ?? "Development"}",
Region = RegionEndpoint.APSoutheast2.SystemName
};
}
}
The following screenshots from Cloudwatch Logs and Insights show the log generated by this code. The enriched property 'A' and MachineName do not appear
I feel like I am missing something obvious, but for the life of me I cannot see it.
Any ideas why the logs are not being enriched?
Many thanks,
M.