Skip to content

Commit

Permalink
adding WebHost console logs when developing (#10629)
Browse files Browse the repository at this point in the history
  • Loading branch information
brettsam authored Nov 14, 2024
1 parent 974ac1c commit 6f7b2d5
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 9 deletions.
5 changes: 3 additions & 2 deletions src/WebJobs.Script.WebHost/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,11 @@
using Microsoft.AspNetCore.Hosting;
using Microsoft.Azure.WebJobs.Script.Config;
using Microsoft.Azure.WebJobs.Script.WebHost.Configuration;
using Microsoft.Azure.WebJobs.Script.WebHost.DependencyInjection;
using Microsoft.Azure.WebJobs.Script.WebHost.Diagnostics;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Configuration.EnvironmentVariables;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.DependencyInjection.Extensions;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
using DataProtectionConstants = Microsoft.Azure.Web.DataProtection.Constants;

Expand Down Expand Up @@ -90,6 +89,8 @@ public static IWebHostBuilder CreateWebHostBuilder(string[] args = null)
loggingBuilder.AddWebJobsSystem<WebHostSystemLoggerProvider>();
loggingBuilder.Services.AddSingleton<DeferredLoggerProvider>();
loggingBuilder.Services.AddSingleton<ILoggerProvider>(s => s.GetRequiredService<DeferredLoggerProvider>());
loggingBuilder.AddConsoleIfEnabled(context.HostingEnvironment.IsDevelopment(), context.Configuration);
})
.UseStartup<Startup>();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,10 @@ private static bool IsFiltered(string category)

public static void AddConsoleIfEnabled(this ILoggingBuilder builder, HostBuilderContext context)
{
AddConsoleIfEnabled(builder, context.HostingEnvironment.IsDevelopment(), context.Configuration);
builder.AddConsoleIfEnabled(context.HostingEnvironment.IsDevelopment(), context.Configuration);
}

public static void AddConsoleIfEnabled(this ILoggingBuilder builder, WebHostBuilderContext context)
{
AddConsoleIfEnabled(builder, context.HostingEnvironment.IsDevelopment(), context.Configuration);
}

private static void AddConsoleIfEnabled(ILoggingBuilder builder, bool isDevelopment, IConfiguration configuration)
public static void AddConsoleIfEnabled(this ILoggingBuilder builder, bool isDevelopment, IConfiguration configuration)
{
// console logging defaults to false, except for self host
bool enableConsole = isDevelopment;
Expand Down

0 comments on commit 6f7b2d5

Please sign in to comment.