Skip to content

Commit

Permalink
UseNLogHost() to be used on IHostBuilder (#11604)
Browse files Browse the repository at this point in the history
  • Loading branch information
jtkech authored May 12, 2022
1 parent 5d3950a commit b2210c2
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
24 changes: 24 additions & 0 deletions src/OrchardCore/OrchardCore.Logging.NLog/HostBuilderExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
using System.IO;
using Microsoft.Extensions.Hosting;
using NLog;
using NLog.LayoutRenderers;
using NLog.Web;

namespace OrchardCore.Logging;

public static class HostBuilderExtensions
{
public static IHostBuilder UseNLogHost(this IHostBuilder builder)
{
LayoutRenderer.Register<TenantLayoutRenderer>(TenantLayoutRenderer.LayoutRendererName);
builder.UseNLog();
builder.ConfigureAppConfiguration((context, _) =>
{
var environment = context.HostingEnvironment;
environment.ConfigureNLog($"{environment.ContentRootPath}{Path.DirectorySeparatorChar}NLog.config");
LogManager.Configuration.Variables["configDir"] = environment.ContentRootPath;
});

return builder;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public static IWebHostBuilder UseNLogWeb(this IWebHostBuilder builder)
{
LayoutRenderer.Register<TenantLayoutRenderer>(TenantLayoutRenderer.LayoutRendererName);
builder.UseNLog();
builder.ConfigureAppConfiguration((context, configuration) =>
builder.ConfigureAppConfiguration((context, _) =>
{
var environment = context.HostingEnvironment;
environment.ConfigureNLog($"{environment.ContentRootPath}{Path.DirectorySeparatorChar}NLog.config");
Expand All @@ -26,7 +26,6 @@ public static IWebHostBuilder UseNLogWeb(this IWebHostBuilder builder)
}
}

// Waiting for NLog to use `IHostEnvironment`.
internal static class AspNetExtensions
{
public static LoggingConfiguration ConfigureNLog(this IHostEnvironment env, string configFileRelativePath)
Expand Down

0 comments on commit b2210c2

Please sign in to comment.