-
Notifications
You must be signed in to change notification settings - Fork 150
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
Configure NLogProviderOptions from appsettings.json #248
Conversation
02f789d
to
227b64f
Compare
I was just preparing 1.3 ;) #247 |
I don't fully understand what this PR is changing. What's the benefit here? |
src/NLog.Extensions.Configuration/ConfigSettingLayoutRenderer.cs
Outdated
Show resolved
Hide resolved
Codecov Report
@@ Coverage Diff @@
## master #248 +/- ##
===========================================
- Coverage 70.19% 58.06% -12.14%
===========================================
Files 9 1 -8
Lines 510 62 -448
Branches 129 17 -112
===========================================
- Hits 358 36 -322
+ Misses 99 15 -84
+ Partials 53 11 -42 Continue to review full report at Codecov.
|
src/NLog.Extensions.Configuration/NLog.Extensions.Configuration.csproj
Outdated
Show resolved
Hide resolved
Not a big AspNet-Core-Expert, but I see lots of people doing this:
Trying to make this layoutrenderer do the same when default configuration. |
shouldn't we do |
Where do I get the hosting environment? Think AppDomain.BaseDirectory is just fine. |
Good one. And always AppDomain.BaseDirectory then? I think it's a bit magic this only done with the "default config". Or is that a breaking (behavior) change? |
Btw. going out now, so will not be able to make any changes. If you need more modifications, then you to push them yourself
Breaking change from what? |
OK have fun |
I can't push on your master :| |
@304NotModified What changes do you like me to make? |
src/NLog.Extensions.Configuration/ConfigSettingLayoutRenderer.cs
Outdated
Show resolved
Hide resolved
c1de8a0
to
431dd5d
Compare
1327a8f
to
30bb4c7
Compare
CaptureMessageProperties = true | ||
loggingBuilder.ClearProviders(); | ||
loggingBuilder.SetMinimumLevel(Microsoft.Extensions.Logging.LogLevel.Trace); | ||
loggingBuilder.AddNLog(config); |
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.
I'm not sure if this is DI-proof.
I think it's a good change to move to the Factory instead of Provider, that's the one we could also bootstrap from DI. See #253
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.
Please explain DI-proof? Adding the NLogLoggerProvider as provider to the official LoggerFactory is the nice way of being part of Microsoft Logging Extensions.
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.
I don't like to change the call, if we need a new dependency. But is a bit debatable if the config is here an dependency or not.
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.
I was planning that NLogLoggingProvider.Options and NLog-LoggingConfiguration was loaded from IConfiguration. So it would be natural to receive the config when doing AddNLog.
But not that skilled with DI and fluent-interface, so any help with creating a great interface is very welcome.
87dcae1
to
03c30fd
Compare
I'm sorry this PR is still open. It's a bit too big for me to handle currently. |
Could we please split this PR into multiple? It's far more easier to read/review/test then. |
Now it just adds support for configuring NLogProviderOptions from appsettings.json. And the ability to provide isolated LogFactory-object. When review complete, then we take the next code-change (Merging NLog.Extension.Configuration into NLog.Extension.Logging). |
9ed4adf
to
1f01704
Compare
506a2bc
to
3c71b3c
Compare
@@ -83,5 +153,48 @@ public static LoggingConfiguration ConfigureNLog(this ILoggerFactory loggerFacto | |||
LogManager.Configuration = config; | |||
return config; | |||
} | |||
|
|||
/// <summary> | |||
/// Factory method for <see cref="NLogLoggerProvider"/> |
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.
this isn't a factory method? (IMO factory method should be called "Create")
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.
Nope it is an extension-method with fluent-interface.
/// <param name="nlogProvider"></param> | ||
/// <param name="configuration">Microsoft Extension Configuration</param> | ||
/// <returns></returns> | ||
public static NLogLoggerProvider ConfigureNLogProvider(this NLogLoggerProvider nlogProvider, IConfiguration 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.
Proposal: Configure
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.
Accepted
var provider = new NLogLoggerProvider(options ?? new NLogProviderOptions()); | ||
if (hostbuilder.Configuration != null) | ||
{ | ||
// TODO ConfigSettingLayoutRenderer.DefaultConfiguration = hostbuilder.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.
when should be do this TODO?
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.
Next PR. You just requested me to split this into more PRs
@@ -33,6 +35,19 @@ public static ILoggerFactory AddNLog(this ILoggerFactory factory, NLogProviderOp | |||
return factory; | |||
} | |||
|
|||
/// <summary> | |||
/// Enable NLog as logging provider in .NET Core. |
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.
not sure if this should be ".NET Standard." instead of ".NET Core"
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.
NetCore is the platform. NetStandard is the API-specification.
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.
But yes lets call it Net Standard since this packages works on both NetCore and NetFramework.
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.
Have updated all comments to say "for Microsoft Extension Logging".
var provider = new NLogLoggerProvider(new NLogProviderOptions()); | ||
if (configuration != null) | ||
{ | ||
// TODO ConfigSettingLayoutRenderer.DefaultConfiguration = 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.
is this TODO for this PR, or do we need a Github issue?
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.
Next PR. You just requested me to split this into more PRs
@@ -40,7 +40,7 @@ public void TestNonSerializableSayHi() | |||
var scopeString = runner.SayHi().Result; | |||
Assert.Single(target.Logs); | |||
Assert.Equal("Hi Earth. Welcome Earth People", target.Logs[0]); | |||
Assert.Equal("Earth People", scopeString); | |||
// Assert.Equal("Earth People", scopeString); <-- Bug https://github.com/aspnet/Logging/issues/893 |
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.
Dunno if this is solved yet, as the repo has been changed/moved (now readonly)
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.
Think it has been resolved in NetCore2.2, but that is not the long-term-support-version (NetCore 2.1 is)
Added support for configuring NLogProviderOptions from appsettings.json (Updated package "Microsoft.Extensions.Logging" from Version="2.0.1" to Version="2.1.0")
Added new NLogLoggerProvider-constructor with LogFactory-parameter