-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
Replace NLog methods that are now obsoletes #13824
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,7 +4,6 @@ | |
using Microsoft.Extensions.Hosting; | ||
using NLog; | ||
using NLog.Config; | ||
using NLog.LayoutRenderers; | ||
using NLog.Web; | ||
|
||
namespace OrchardCore.Logging | ||
|
@@ -13,7 +12,9 @@ public static class WebHostBuilderExtensions | |
{ | ||
public static IWebHostBuilder UseNLogWeb(this IWebHostBuilder builder) | ||
{ | ||
LayoutRenderer.Register<TenantLayoutRenderer>(TenantLayoutRenderer.LayoutRendererName); | ||
LogManager.Setup().SetupExtensions(builder => | ||
builder.RegisterLayoutRenderer<TenantLayoutRenderer>(TenantLayoutRenderer.LayoutRendererName)); | ||
|
||
builder.UseNLog(); | ||
builder.ConfigureAppConfiguration((context, _) => | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Notice that So
|
||
{ | ||
|
@@ -30,10 +31,12 @@ internal static class AspNetExtensions | |
{ | ||
public static LoggingConfiguration ConfigureNLog(this IHostEnvironment env, string configFileRelativePath) | ||
{ | ||
ConfigurationItemFactory.Default.RegisterItemsFromAssembly(typeof(AspNetExtensions).GetTypeInfo().Assembly); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Instead of depending on assembly-scanning, then it could nice if just doing registration of the single custom LayoutRenderer: var fileName = Path.Combine(env.ContentRootPath, configFileRelativePath);
LogManager.Setup().SetupLogFactory(factory => factory.AddCallSiteHiddenAssembly(typeof(AspNetExtensions).GetTypeInfo().Assembly))
.SetupExtensions(ext => {
ext.RegisterLayoutRenderer<TenantLayoutRenderer>(TenantLayoutRenderer.LayoutRendererName);
ext.RegisterNLogWeb();
})
.LoadConfigurationFromFile(fileName);
return LogManager.Configuration; |
||
LogManager.Setup().SetupExtensions(builder => | ||
builder.RegisterAssembly(typeof(AspNetExtensions).GetType().Assembly)); | ||
|
||
LogManager.AddHiddenAssembly(typeof(AspNetExtensions).GetTypeInfo().Assembly); | ||
var fileName = Path.Combine(env.ContentRootPath, configFileRelativePath); | ||
LogManager.LoadConfiguration(fileName); | ||
LogManager.Setup().LoadConfigurationFromFile(fileName); | ||
return LogManager.Configuration; | ||
} | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Notice that
builder.UseNLog()
with NLog.Web.AspNetCore v5, will automatically loadnlog.config
from theenv.ContentRootPath
.So
ConfigureAppConfiguration
could be changed to just: