AspNetCoreServer and Duplicate Logging
See original GitHub issueWe’re currently experiencing an issue with Amazon.Lambda.AspNetCoreServer and Logging.
We’re hosting an asp.net core web site in Lambda. The web site works however I’m getting duplicates in the logs in CloudWatch and I haven’t been able to figure out the cause. I’ve removed all the logging setup identified in Amazon.Lambda.Logging.AspNetCore and the behaviour is exactly the same regardless. App settings also has no logging configuration.
Here is an example of what I’m seeing in the log:
- 2020-06-20T20:50:56.705-04:00 START RequestId: fdbd1980-8263-4b5f-8bfc-ef8ec43e0085 Version: $LATEST
- 2020-06-20T20:50:56.705-04:00 [40m[32minfo[39m[22m[49m: Microsoft.Hosting.Lifetime[0]
- 2020-06-20T20:50:56.707-04:00 Application started. Press Ctrl+C to shut down.
- 2020-06-20T20:50:56.708-04:00 [Information] Microsoft.Hosting.Lifetime: Application started. Press Ctrl+C to shut down.
- 2020-06-20T20:50:56.708-04:00 [40m[32minfo[39m[22m[49m: Microsoft.Hosting.Lifetime[0]
- 2020-06-20T20:50:56.708-04:00 Hosting environment: Production
- 2020-06-20T20:50:56.708-04:00 [40m[32minfo[39m[22m[49m: Microsoft.Hosting.Lifetime[0]
- 2020-06-20T20:50:56.708-04:00 Content root path: /var/task
- 2020-06-20T20:50:56.708-04:00 [Information] Microsoft.Hosting.Lifetime: Hosting environment: Production
- 2020-06-20T20:50:56.708-04:00 [Information] Microsoft.Hosting.Lifetime: Content root path: /var/task
- 2020-06-20T20:50:56.880-04:00 [40m[32minfo[39m[22m[49m: Microsoft.AspNetCore.Hosting.Diagnostics[1]
- 2020-06-20T20:50:57.456-04:00 [Information] Project.Classes.GetFileHandler: Started Project.Classes.GetFileHandler
- 2020-06-20T20:50:57.456-04:00 Started Project.Classes.GetFileHandler
Below is a simplified version of my code.
public class LambdaEntryPoint : Amazon.Lambda.AspNetCoreServer.APIGatewayProxyFunction
{
protected override void Init(IWebHostBuilder builder)
{
RegisterResponseContentEncodingForContentType("application/pdf",
ResponseContentEncoding.Base64);
builder
.UseStartup<Startup>();
}
protected override void Init(IHostBuilder builder)
{
}
}
public class Startup
{
public Startup(IConfiguration configuration)
{
Configuration = configuration;
}
public IConfiguration Configuration { get; }
public void ConfigureServices(IServiceCollection services)
{
IConfigurationSection appSettings = Configuration.GetSection("AppSettings");
services.Configure<AppSettings>(appSettings);
services.AddAWSService<IAmazonS3>();
}
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
else
{
app.UseExceptionHandler("/Error");
// The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
app.UseHsts();
}
app.UseHttpsRedirection();
app.UseStaticFiles();
app.UseRouting();
app.MapWhen(
context => context.Request.Path.ToString().EndsWith("file.ashx"),
appBranch => {
// ... optionally add more middleware to this branch
appBranch.UseGetFileHandler();
});
}
}
public class GetFileHandler
{
public GetFileHandler(RequestDelegate next)
{ }
public async Task Invoke(HttpContext context, ILogger<GetFileHandler> logger)
{
logger.LogInformation("Started " + this.GetType());
}
}
Thanks for any help.
Regards Artin
Issue Analytics
- State:
- Created 3 years ago
- Comments:11 (2 by maintainers)
Top Results From Across the Web
Serilog duplicate log statements - asp.net core
Console in Program.cs , output to console duplicate cause you have two WriteTo.Console , One from appSetting.json , one from builder.
Read more >Logging in .NET Core and ASP.NET Core
Logging set to Logging:Console:LogLevel:Microsoft:Information . Navigation to the Privacy page: Console Copy. info: Microsoft.AspNetCore.
Read more >Logging and diagnostics in Kestrel
Logging to emit log information. Kestrel employs the use of multiple categories which allows you to be selective on which logs you listen...
Read more >c# - Simple way to prevent duplicate logging of errors
I've been tasked with updating our current error logging system to prevent the logging of similar errors (from a single client program) that ......
Read more >Serilog.Extensions.Logging 3.1.1-dev-10338
Low-level Serilog provider for Microsoft.Extensions.Logging. ... then a potentially very large block of text would be duplicated within your log event!
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I resolved it by using the work around I specified. Specifically clearing the providers set by the library and resetting them myself. I don’t know if the underlying issue has been resolved.
I’ve been able to work around the issue by doing the following in the LambdaEntryPoint class:
Haven’t been able to figure out what in the base class would be causing this issue.