i currently have a very basic .NET 5 Blazor Server App running at my azure app service.
Deployment works as expected, app is running and i can call my service properly. Now i tried to add logging to azure stream and it worked sometimes, now not anymore for a not known reason. Following is happening in error state:
I have configured logging within Program.cs in CreateHostBuilder
public static IHostBuilder CreateHostBuilder(string[] args) => Host.CreateDefaultBuilder(args) .ConfigureLogging(logging => { logging.ClearProviders(); //logging.AddAzureWebAppDiagnostics(); //<== NEVER EVER add this again in .net core as it is implicit called and will cause missing logs!!!: https://wakeupandcode.com/logging-in-asp-net-core/ logging.AddConsole(); logging.AddDebug(); }) .ConfigureServices(serviceCollection => serviceCollection .Configure<AzureFileLoggerOptions>(options => { options.FileName = $"{DateTime.UtcNow.Hour.ToString()}_{Assembly.GetExecutingAssembly().GetName().Name}_diagnostics_"; options.FileSizeLimit = 50 * 1024; options.RetainedFileCountLimit = 5; })) .ConfigureWebHostDefaults(webBuilder => { webBuilder.UseStartup<Startup>(); }); As you may see i commented AddAzureWebAppDiagnostics out as it is implicit called from framework when deployed to azure, so there is no need to call it explicitly! AND I had this issue short time before, and when i commented it out logging worked fine again, so i thought this was the problem... it was not!
Now problem occured again, so more details:
I use this configured logging first in startup.cs
public void Configure(IApplicationBuilder app, IWebHostEnvironment env, ILogger<Startup> logger) { _logger = logger; this._logger.LogPrettyInformation($"Current Environment is: {env.EnvironmentName}"); if (env.IsDevelopment() || env.IsStaging()) { string envi = env.IsDevelopment() ? EnvironmentEnum.Development.ToString() : EnvironmentEnum.Staging.ToString(); this._logger.LogPrettyInformation($"Met condition for: {envi}"); app.UseDeveloperExceptionPage(); } else if (env.EnvironmentName.Equals(EnvironmentEnum.Debug.ToString())) { this._logger.LogPrettyInformation($"Met condition for: {EnvironmentEnum.Debug.ToString()}"); app.UseDeveloperExceptionPage(); } else if (env.IsProduction()) { this._logger.LogPrettyInformation($"Met condition for: {EnvironmentEnum.Production.ToString()}"); 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.UseAuthentication(); app.UseAuthorization(); app.UseEndpoints(endpoints => { endpoints.MapControllers(); endpoints.MapBlazorHub(); endpoints.MapFallbackToPage("/_Host"); }); } These lines with all that LogPretty-stuff are all working just fine! I can see them at my local debbuging output AND at azure protocol stream too! Looks good ha?
Now I use DI to log from pages and services and stuff, this is the part that is not working any more, but worked from time to time. Now when i call my Counter page as brought up to me by the VS template (WeatherForecastService is the same issue...) I have some logs after i increase the count. But they are only shown in Debug output in my Visual Studio debugging session, NOT in my azure stream.
Any Ideas? In short:
- all logs working fine in debug session (output window)
- logs from startup working fine in debug and in azure stream and of course in filesystem under application as configured
- others not! Not in file and not in stream, just in debug output!
Method for logging - LogPretty - is not throwing any exception.
Thank you guys!
