Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UseNLogHost() to be used on IHostBuilder #11604

Merged
merged 1 commit into from
May 12, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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