-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Replace NLog methods that are now obsoletes (#13824)
- Loading branch information
Showing
2 changed files
with
35 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 26 additions & 22 deletions
48
src/OrchardCore/OrchardCore.Logging.NLog/WebHostBuilderExtensions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,40 +1,44 @@ | ||
using System.IO; | ||
using System.Reflection; | ||
using Microsoft.AspNetCore.Hosting; | ||
using Microsoft.Extensions.Hosting; | ||
using NLog; | ||
using NLog.Config; | ||
using NLog.LayoutRenderers; | ||
using NLog.Web; | ||
|
||
namespace OrchardCore.Logging | ||
namespace OrchardCore.Logging; | ||
|
||
public static class WebHostBuilderExtensions | ||
{ | ||
public static class WebHostBuilderExtensions | ||
public static IWebHostBuilder UseNLogWeb(this IWebHostBuilder builder) | ||
{ | ||
public static IWebHostBuilder UseNLogWeb(this IWebHostBuilder builder) | ||
{ | ||
LayoutRenderer.Register<TenantLayoutRenderer>(TenantLayoutRenderer.LayoutRendererName); | ||
builder.UseNLog(); | ||
builder.ConfigureAppConfiguration((context, _) => | ||
LogManager.Setup().SetupExtensions(ext => | ||
ext.RegisterLayoutRenderer<TenantLayoutRenderer>(TenantLayoutRenderer.LayoutRendererName)); | ||
|
||
return builder | ||
.UseNLog() | ||
.ConfigureAppConfiguration((context, _) => | ||
{ | ||
var environment = context.HostingEnvironment; | ||
environment.ConfigureNLog($"{environment.ContentRootPath}{Path.DirectorySeparatorChar}NLog.config"); | ||
LogManager.Configuration.Variables["configDir"] = environment.ContentRootPath; | ||
}); | ||
|
||
return builder; | ||
} | ||
} | ||
} | ||
|
||
internal static class AspNetExtensions | ||
internal static class AspNetExtensions | ||
{ | ||
public static LoggingConfiguration ConfigureNLog(this IHostEnvironment env, string configFileRelativePath) | ||
{ | ||
public static LoggingConfiguration ConfigureNLog(this IHostEnvironment env, string configFileRelativePath) | ||
{ | ||
ConfigurationItemFactory.Default.RegisterItemsFromAssembly(typeof(AspNetExtensions).GetTypeInfo().Assembly); | ||
LogManager.AddHiddenAssembly(typeof(AspNetExtensions).GetTypeInfo().Assembly); | ||
var fileName = Path.Combine(env.ContentRootPath, configFileRelativePath); | ||
LogManager.LoadConfiguration(fileName); | ||
return LogManager.Configuration; | ||
} | ||
var fileName = Path.Combine(env.ContentRootPath, configFileRelativePath); | ||
|
||
LogManager.Setup() | ||
.SetupLogFactory(factory => factory.AddCallSiteHiddenAssembly(typeof(AspNetExtensions).GetType().Assembly)) | ||
.SetupExtensions(ext => | ||
{ | ||
ext.RegisterLayoutRenderer<TenantLayoutRenderer>(TenantLayoutRenderer.LayoutRendererName); | ||
ext.RegisterNLogWeb(); | ||
}) | ||
.LoadConfigurationFromFile(fileName); | ||
|
||
return LogManager.Configuration; | ||
} | ||
} |