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

Configure NLogProviderOptions from appsettings.json #248

Merged
merged 3 commits into from Jan 13, 2019

Conversation

snakefoot
Copy link
Contributor

@snakefoot snakefoot commented Sep 22, 2018

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

@304NotModified
Copy link
Member

304NotModified commented Sep 22, 2018

I was just preparing 1.3 ;) #247

@304NotModified
Copy link
Member

I don't fully understand what this PR is changing. What's the benefit here?

@codecov
Copy link

codecov bot commented Sep 22, 2018

Codecov Report

Merging #248 into master will decrease coverage by 12.13%.
The diff coverage is n/a.

Impacted file tree graph

@@             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
Impacted Files Coverage Δ
...nsions.Logging/Logging/NLogMessageParameterList.cs
....Extensions.Logging/Logging/NLogProviderOptions.cs
src/NLog.Extensions.Logging/Logging/NLogLogger.cs
...og.Extensions.Logging/Logging/NLogLoggerFactory.cs
...Extensions.Logging/Logging/NLogBeginScopeParser.cs

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 13a841c...87369ca. Read the comment docs.

@snakefoot
Copy link
Contributor Author

I don't fully understand what this PR is changing. What's the benefit here?

Not a big AspNet-Core-Expert, but I see lots of people doing this:

   var builder = new ConfigurationBuilder()
        .SetBasePath(env.ContentRootPath)
        .AddJsonFile("appsettings.json", optional: false, reloadOnChange: true)
        .AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true)
        .AddEnvironmentVariables();

Trying to make this layoutrenderer do the same when default configuration.

@304NotModified
Copy link
Member

shouldn't we do .SetBasePath(env.ContentRootPath) then always?

@snakefoot
Copy link
Contributor Author

snakefoot commented Sep 22, 2018

shouldn't we do .SetBasePath(env.ContentRootPath) then always?

Where do I get the hosting environment? Think AppDomain.BaseDirectory is just fine.

@304NotModified
Copy link
Member

Where do I get the hosting environment?

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?

@snakefoot
Copy link
Contributor Author

Btw. going out now, so will not be able to make any changes. If you need more modifications, then you to push them yourself

Or is that a breaking (behavior) change?

Breaking change from what?

@304NotModified
Copy link
Member

OK have fun

@304NotModified 304NotModified added this to the 1.3.1 milestone Sep 22, 2018
@304NotModified
Copy link
Member

I can't push on your master :|

@snakefoot
Copy link
Contributor Author

@304NotModified What changes do you like me to make?

@snakefoot snakefoot changed the title configsetting - Include AddEnvironmentVariables when default config configsetting - Remove EnvironmentVariables dependency Sep 23, 2018
CaptureMessageProperties = true
loggingBuilder.ClearProviders();
loggingBuilder.SetMinimumLevel(Microsoft.Extensions.Logging.LogLevel.Trace);
loggingBuilder.AddNLog(config);
Copy link
Member

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

Copy link
Contributor Author

@snakefoot snakefoot Oct 12, 2018

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.

Copy link
Member

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.

Copy link
Contributor Author

@snakefoot snakefoot Oct 12, 2018

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.

@304NotModified
Copy link
Member

I'm sorry this PR is still open. It's a bit too big for me to handle currently.

@304NotModified
Copy link
Member

Could we please split this PR into multiple? It's far more easier to read/review/test then.

@snakefoot snakefoot changed the title moved ${configsetting} to NLog.Extensions.Logging package. Removed filename property. Updated UseNLog/AddNLog. NLogLoggerProvider - Added constructor with isolated NLog LogFactory Jan 12, 2019
@snakefoot
Copy link
Contributor Author

snakefoot commented Jan 12, 2019

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).

@snakefoot snakefoot force-pushed the master branch 5 times, most recently from 9ed4adf to 1f01704 Compare January 12, 2019 14:08
@snakefoot snakefoot changed the title NLogLoggerProvider - Added constructor with isolated NLog LogFactory Configure NLogProviderOptions from appsettings.json Jan 12, 2019
@snakefoot snakefoot force-pushed the master branch 2 times, most recently from 506a2bc to 3c71b3c Compare January 12, 2019 14:32
@304NotModified 304NotModified modified the milestones: 1.3.1, 1.4 Jan 13, 2019
@@ -83,5 +153,48 @@ public static LoggingConfiguration ConfigureNLog(this ILoggerFactory loggerFacto
LogManager.Configuration = config;
return config;
}

/// <summary>
/// Factory method for <see cref="NLogLoggerProvider"/>
Copy link
Member

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")

Copy link
Contributor Author

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)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Proposal: Configure

Copy link
Contributor Author

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;
Copy link
Member

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?

Copy link
Contributor Author

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.
Copy link
Member

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"

Copy link
Contributor Author

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.

Copy link
Contributor Author

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.

Copy link
Contributor Author

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;
Copy link
Member

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?

Copy link
Contributor Author

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
Copy link
Member

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)

Copy link
Contributor Author

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)

@304NotModified 304NotModified merged commit 86ce1c1 into NLog:master Jan 13, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants