diff --git a/NLog.Extensions.Logging.sln b/NLog.Extensions.Logging.sln
index cf14af65..631b3ddf 100644
--- a/NLog.Extensions.Logging.sln
+++ b/NLog.Extensions.Logging.sln
@@ -8,6 +8,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
ProjectSection(SolutionItems) = preProject
appveyor.yml = appveyor.yml
build.ps1 = build.ps1
+ CHANGELOG.MD = CHANGELOG.MD
README.md = README.md
EndProjectSection
EndProject
diff --git a/build.ps1 b/build.ps1
index 90751251..b9abb9e0 100644
--- a/build.ps1
+++ b/build.ps1
@@ -2,8 +2,8 @@
# creates NuGet package at \artifacts
dotnet --version
-$versionPrefix = "1.4.0"
-$versionSuffix = ""
+$versionPrefix = "1.5.0"
+$versionSuffix = "rc1"
$versionFile = $versionPrefix + "." + ${env:APPVEYOR_BUILD_NUMBER}
$versionProduct = $versionPrefix;
if (-Not $versionSuffix.Equals(""))
diff --git a/examples/NetCore2/ConsoleExample/ConsoleExample.csproj b/examples/NetCore2/ConsoleExample/ConsoleExample.csproj
index b86064c9..c5eefde4 100644
--- a/examples/NetCore2/ConsoleExample/ConsoleExample.csproj
+++ b/examples/NetCore2/ConsoleExample/ConsoleExample.csproj
@@ -11,7 +11,6 @@
-
diff --git a/examples/NetCore2/ConsoleExample/Program.cs b/examples/NetCore2/ConsoleExample/Program.cs
index b7d8be6b..c1981efb 100644
--- a/examples/NetCore2/ConsoleExample/Program.cs
+++ b/examples/NetCore2/ConsoleExample/Program.cs
@@ -12,9 +12,17 @@ internal class Program
private static void Main()
{
var logger = LogManager.GetCurrentClassLogger();
+
try
{
- var servicesProvider = BuildDi();
+ var config = new ConfigurationBuilder()
+ .SetBasePath(System.IO.Directory.GetCurrentDirectory())
+ .AddJsonFile("appsettings.json", optional: true, reloadOnChange: true)
+ .Build();
+
+ LogManager.Configuration = new ExtensionLoggingConfiguration(config.GetSection("NLog"));
+
+ var servicesProvider = BuildDi(config);
using (servicesProvider as IDisposable)
{
var runner = servicesProvider.GetRequiredService();
@@ -37,28 +45,18 @@ private static void Main()
}
}
- private static IServiceProvider BuildDi()
+ private static IServiceProvider BuildDi(IConfiguration config)
{
- var services = new ServiceCollection();
-
- // Runner is the custom class
- services.AddTransient();
-
- var config = new ConfigurationBuilder()
- .SetBasePath(System.IO.Directory.GetCurrentDirectory())
- .AddJsonFile("appsettings.json", optional: true, reloadOnChange: true)
- .Build();
-
- // configure Logging with NLog
- services.AddLogging(loggingBuilder =>
- {
- loggingBuilder.ClearProviders();
- loggingBuilder.SetMinimumLevel(Microsoft.Extensions.Logging.LogLevel.Trace);
- loggingBuilder.AddNLog(config);
- });
-
- var serviceProvider = services.BuildServiceProvider();
- return serviceProvider;
+ return new ServiceCollection()
+ .AddTransient() // Runner is the custom class
+ .AddLogging(loggingBuilder =>
+ {
+ // configure Logging with NLog
+ loggingBuilder.ClearProviders();
+ loggingBuilder.SetMinimumLevel(Microsoft.Extensions.Logging.LogLevel.Trace);
+ loggingBuilder.AddNLog(config);
+ })
+ .BuildServiceProvider();
}
}
diff --git a/examples/NetCore2/ConsoleExample/appsettings.json b/examples/NetCore2/ConsoleExample/appsettings.json
index daabc235..352cad2f 100644
--- a/examples/NetCore2/ConsoleExample/appsettings.json
+++ b/examples/NetCore2/ConsoleExample/appsettings.json
@@ -5,5 +5,43 @@
"ParseMessageTemplates": true,
"CaptureMessageProperties": true
}
+ },
+ "NLog": {
+ "autoreload": true,
+ "internalLogLevel": "Info",
+ "internalLogFile": "c:/temp/console-example-internal.log",
+ "throwConfigExceptions": true,
+ "targets": {
+ "console": {
+ "type": "Console",
+ "layout": "${date}|${level:uppercase=true}|${message} ${exception:format=tostring}|${logger}|${all-event-properties}"
+ },
+ "file": {
+ "type": "AsyncWrapper",
+ "target": {
+ "wrappedFile": {
+ "type": "File",
+ "fileName": "c:/temp/console-example.log",
+ "layout": {
+ "type": "JsonLayout",
+ "Attributes": [
+ { "name": "timestamp", "layout": "${date:format=o}" },
+ { "name": "level", "layout": "${level}" },
+ { "name": "logger", "layout": "${logger}" },
+ { "name": "message", "layout": "${message:raw=true}" },
+ { "name": "properties", "encode": false, "layout": { "type": "JsonLayout", "includeallproperties": "true" } }
+ ]
+ }
+ }
+ }
+ }
+ },
+ "rules": [
+ {
+ "logger": "*",
+ "minLevel": "Trace",
+ "writeTo": "File,Console"
+ }
+ ]
}
}
\ No newline at end of file
diff --git a/src/NLog.Extensions.Logging/Config/ExtensionLoggingConfiguration.cs b/src/NLog.Extensions.Logging/Config/ExtensionLoggingConfiguration.cs
new file mode 100644
index 00000000..43ca9996
--- /dev/null
+++ b/src/NLog.Extensions.Logging/Config/ExtensionLoggingConfiguration.cs
@@ -0,0 +1,107 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using Microsoft.Extensions.Configuration;
+using NLog.Config;
+
+namespace NLog.Extensions.Logging
+{
+ ///
+ /// Configures NLog through Microsoft Extension Configuration section (Ex from appsettings.json)
+ ///
+ public class ExtensionLoggingConfiguration : LoggingConfigurationParser
+ {
+ private readonly Action