diff --git a/.travis.yml b/.travis.yml index 50489b68..9d00bbe4 100644 --- a/.travis.yml +++ b/.travis.yml @@ -17,8 +17,11 @@ install: # Restore dependencies - dotnet restore src/NLog.Extensions.Logging - - dotnet restore test + - dotnet restore src/NLog.Extensions.Hosting + - dotnet restore test/NLog.Extensions.Hosting.Tests + - dotnet restore test/NLog.Extensions.Logging.Tests script: # Run tests - - dotnet test test --configuration Release --framework netcoreapp2.0 + - dotnet test test/NLog.Extensions.Hosting.Tests --configuration Release --framework netcoreapp2.0 + - dotnet test test/NLog.Extensions.Logging.Tests --configuration Release --framework netcoreapp2.0 diff --git a/NLog.Extensions.Logging.sln b/NLog.Extensions.Logging.sln index 19e3fc60..62e12c90 100644 --- a/NLog.Extensions.Logging.sln +++ b/NLog.Extensions.Logging.sln @@ -6,13 +6,19 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{C21FD102-21B EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{BD106966-02BE-4137-B9DC-4ECE56B4C204}" EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "NLog.Extensions.Logging", "src\NLog.Extensions.Logging\NLog.Extensions.Logging.csproj", "{5BB808CD-F633-47C7-98B0-79B2A9BAE24A}" -EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "NLog.Extensions.Logging.Tests", "test\NLog.Extensions.Logging.Tests.csproj", "{7D396A98-C026-4C20-8F5E-2EA76A14CA7D}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "NLog.Extensions.Logging", "src\NLog.Extensions.Logging\NLog.Extensions.Logging.csproj", "{6A236D76-C9D9-4B1D-8DDE-F6978D110288}" EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "test", "test", "{FBD2E07B-F25B-4D2F-AEF6-6D1E10F1E523}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ConsoleExample", "Examples\NetCore2\ConsoleExample\ConsoleExample.csproj", "{CF2D8DDE-5876-4EF0-B99D-3C536E887E18}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ConsoleExample", "Examples\NetCore2\ConsoleExample\ConsoleExample.csproj", "{CF2D8DDE-5876-4EF0-B99D-3C536E887E18}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "NLog.Extensions.Hosting", "src\NLog.Extensions.Hosting\NLog.Extensions.Hosting.csproj", "{548E65CE-0378-4812-AE00-B173F1251D3C}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "NLog.Extensions.Hosting.Tests", "test\NLog.Extensions.Hosting.Tests\NLog.Extensions.Hosting.Tests.csproj", "{0DC000BA-2DF8-48E5-A7BC-D76CB9D3FC61}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "NLog.Extensions.Logging.Tests", "test\NLog.Extensions.Logging.Tests\NLog.Extensions.Logging.Tests.csproj", "{DC42BF57-6316-4FCA-AD33-48FFDAFB4712}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "HostingExample", "examples\NetCore2\HostingExample\HostingExample.csproj", "{07D358DF-D77A-434B-B034-95785DF7106F}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -20,26 +26,41 @@ Global Release|Any CPU = Release|Any CPU EndGlobalSection GlobalSection(ProjectConfigurationPlatforms) = postSolution - {5BB808CD-F633-47C7-98B0-79B2A9BAE24A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {5BB808CD-F633-47C7-98B0-79B2A9BAE24A}.Debug|Any CPU.Build.0 = Debug|Any CPU - {5BB808CD-F633-47C7-98B0-79B2A9BAE24A}.Release|Any CPU.ActiveCfg = Release|Any CPU - {5BB808CD-F633-47C7-98B0-79B2A9BAE24A}.Release|Any CPU.Build.0 = Release|Any CPU - {7D396A98-C026-4C20-8F5E-2EA76A14CA7D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {7D396A98-C026-4C20-8F5E-2EA76A14CA7D}.Debug|Any CPU.Build.0 = Debug|Any CPU - {7D396A98-C026-4C20-8F5E-2EA76A14CA7D}.Release|Any CPU.ActiveCfg = Release|Any CPU - {7D396A98-C026-4C20-8F5E-2EA76A14CA7D}.Release|Any CPU.Build.0 = Release|Any CPU + {6A236D76-C9D9-4B1D-8DDE-F6978D110288}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {6A236D76-C9D9-4B1D-8DDE-F6978D110288}.Debug|Any CPU.Build.0 = Debug|Any CPU + {6A236D76-C9D9-4B1D-8DDE-F6978D110288}.Release|Any CPU.ActiveCfg = Release|Any CPU + {6A236D76-C9D9-4B1D-8DDE-F6978D110288}.Release|Any CPU.Build.0 = Release|Any CPU {CF2D8DDE-5876-4EF0-B99D-3C536E887E18}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {CF2D8DDE-5876-4EF0-B99D-3C536E887E18}.Debug|Any CPU.Build.0 = Debug|Any CPU {CF2D8DDE-5876-4EF0-B99D-3C536E887E18}.Release|Any CPU.ActiveCfg = Release|Any CPU {CF2D8DDE-5876-4EF0-B99D-3C536E887E18}.Release|Any CPU.Build.0 = Release|Any CPU + {548E65CE-0378-4812-AE00-B173F1251D3C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {548E65CE-0378-4812-AE00-B173F1251D3C}.Debug|Any CPU.Build.0 = Debug|Any CPU + {548E65CE-0378-4812-AE00-B173F1251D3C}.Release|Any CPU.ActiveCfg = Release|Any CPU + {548E65CE-0378-4812-AE00-B173F1251D3C}.Release|Any CPU.Build.0 = Release|Any CPU + {0DC000BA-2DF8-48E5-A7BC-D76CB9D3FC61}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {0DC000BA-2DF8-48E5-A7BC-D76CB9D3FC61}.Debug|Any CPU.Build.0 = Debug|Any CPU + {0DC000BA-2DF8-48E5-A7BC-D76CB9D3FC61}.Release|Any CPU.ActiveCfg = Release|Any CPU + {0DC000BA-2DF8-48E5-A7BC-D76CB9D3FC61}.Release|Any CPU.Build.0 = Release|Any CPU + {DC42BF57-6316-4FCA-AD33-48FFDAFB4712}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {DC42BF57-6316-4FCA-AD33-48FFDAFB4712}.Debug|Any CPU.Build.0 = Debug|Any CPU + {DC42BF57-6316-4FCA-AD33-48FFDAFB4712}.Release|Any CPU.ActiveCfg = Release|Any CPU + {DC42BF57-6316-4FCA-AD33-48FFDAFB4712}.Release|Any CPU.Build.0 = Release|Any CPU + {07D358DF-D77A-434B-B034-95785DF7106F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {07D358DF-D77A-434B-B034-95785DF7106F}.Debug|Any CPU.Build.0 = Debug|Any CPU + {07D358DF-D77A-434B-B034-95785DF7106F}.Release|Any CPU.ActiveCfg = Release|Any CPU + {07D358DF-D77A-434B-B034-95785DF7106F}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE EndGlobalSection GlobalSection(NestedProjects) = preSolution - {5BB808CD-F633-47C7-98B0-79B2A9BAE24A} = {C21FD102-21B1-46DB-AD62-86692558AD01} - {7D396A98-C026-4C20-8F5E-2EA76A14CA7D} = {FBD2E07B-F25B-4D2F-AEF6-6D1E10F1E523} + {6A236D76-C9D9-4B1D-8DDE-F6978D110288} = {C21FD102-21B1-46DB-AD62-86692558AD01} {CF2D8DDE-5876-4EF0-B99D-3C536E887E18} = {BD106966-02BE-4137-B9DC-4ECE56B4C204} + {548E65CE-0378-4812-AE00-B173F1251D3C} = {C21FD102-21B1-46DB-AD62-86692558AD01} + {0DC000BA-2DF8-48E5-A7BC-D76CB9D3FC61} = {FBD2E07B-F25B-4D2F-AEF6-6D1E10F1E523} + {DC42BF57-6316-4FCA-AD33-48FFDAFB4712} = {FBD2E07B-F25B-4D2F-AEF6-6D1E10F1E523} + {07D358DF-D77A-434B-B034-95785DF7106F} = {BD106966-02BE-4137-B9DC-4ECE56B4C204} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {46DF0C22-7B6A-4A64-BC63-7B2F6A14F334} diff --git a/appveyor.yml b/appveyor.yml index a0c5eb74..ca90b067 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -13,14 +13,18 @@ install: build_script: - ps: .\build.ps1 + +nuget: + disable_publish_on_pr: true artifacts: - path: 'artifacts\*.nupkg' test_script: - nuget.exe install OpenCover -ExcludeVersion -DependencyVersion Ignore - - OpenCover\tools\OpenCover.Console.exe -register:user -target:"C:/Program Files/dotnet/dotnet.exe" -targetargs:"test -f netcoreapp1.1" -filter:"+[NLog.Extensions.Logging]* -[NLog.Extensions.Logging.Tests]*" -output:"coverage.xml" -oldstyle -targetdir:"test" - - OpenCover\tools\OpenCover.Console.exe -register:user -mergeoutput -target:"C:/Program Files/dotnet/dotnet.exe" -targetargs:"test -f netcoreapp2.0" -filter:"+[NLog.Extensions.Logging]* -[NLog.Extensions.Logging.Tests]*" -output:"coverage.xml" -oldstyle -targetdir:"test" + - OpenCover\tools\OpenCover.Console.exe -register:user -target:"C:/Program Files/dotnet/dotnet.exe" -targetargs:"test -f netcoreapp1.1 NLog.Extensions.Logging.Tests" -filter:"+[NLog.Extensions.Logging]* +[NLog.Extensions.Hosting]* -[NLog.Extensions.Logging.Tests]* -[NLog.Extensions.Hosting.Tests]*" -output:"coverage.xml" -oldstyle -targetdir:"test" + - OpenCover\tools\OpenCover.Console.exe -register:user -mergeoutput -target:"C:/Program Files/dotnet/dotnet.exe" -targetargs:"test -f netcoreapp2.0 NLog.Extensions.Logging.Tests" -filter:"+[NLog.Extensions.Logging]* +[NLog.Extensions.Hosting]* -[NLog.Extensions.Logging.Tests]* -[NLog.Extensions.Hosting.Tests]*" -output:"coverage.xml" -oldstyle -targetdir:"test" + - OpenCover\tools\OpenCover.Console.exe -register:user -mergeoutput -target:"C:/Program Files/dotnet/dotnet.exe" -targetargs:"test -f netcoreapp2.0 NLog.Extensions.Hosting.Tests" -filter:"+[NLog.Extensions.Logging]* +[NLog.Extensions.Hosting]* -[NLog.Extensions.Logging.Tests]* -[NLog.Extensions.Hosting.Tests]*" -output:"coverage.xml" -oldstyle -targetdir:"test" - pip install codecov - codecov -f "coverage.xml" - ps: .\run-sonar.ps1 diff --git a/build.ps1 b/build.ps1 index e7ac5981..16b0a697 100644 --- a/build.ps1 +++ b/build.ps1 @@ -9,7 +9,19 @@ $versionProduct = $versionPrefix; if (-Not $versionSuffix.Equals("")) { $versionProduct = $versionProduct + "-" + $versionSuffix } -msbuild /t:Restore,Pack .\src\NLog.Extensions.Logging\ /p:targetFrameworks='"net451;net461;netstandard1.3;netstandard1.5;netstandard2.0"' /p:VersionPrefix=$versionPrefix /p:VersionSuffix=$versionSuffix /p:FileVersion=$versionFile /p:ProductVersion=$versionProduct /p:Configuration=Release /p:IncludeSymbols=true /p:PackageOutputPath=..\..\artifacts /verbosity:minimal +dotnet restore .\src\NLog.Extensions.Logging\ +if (-Not $LastExitCode -eq 0) + { exit $LastExitCode } + +dotnet restore .\src\NLog.Extensions.Hosting\ +if (-Not $LastExitCode -eq 0) + { exit $LastExitCode } + +msbuild /t:Pack .\src\NLog.Extensions.Logging\ /p:targetFrameworks='"net451;net461;netstandard1.3;netstandard1.5;netstandard2.0"' /p:VersionPrefix=$versionPrefix /p:VersionSuffix=$versionSuffix /p:FileVersion=$versionFile /p:ProductVersion=$versionProduct /p:Configuration=Release /p:IncludeSymbols=true /p:PackageOutputPath=..\..\artifacts /verbosity:minimal +if (-Not $LastExitCode -eq 0) + { exit $LastExitCode } + +msbuild /t:Pack .\src\NLog.Extensions.Hosting\ /p:targetFrameworks='"netstandard2.0"' /p:VersionPrefix=$versionPrefix /p:VersionSuffix=$versionSuffix /p:FileVersion=$versionFile /p:ProductVersion=$versionProduct /p:Configuration=Release /p:IncludeSymbols=true /p:PackageOutputPath=..\..\artifacts /verbosity:minimal if (-Not $LastExitCode -eq 0) { exit $LastExitCode } diff --git a/examples/NetCore2/ConsoleExample/ConsoleExample.csproj b/examples/NetCore2/ConsoleExample/ConsoleExample.csproj index ddad318b..f8ea3f72 100644 --- a/examples/NetCore2/ConsoleExample/ConsoleExample.csproj +++ b/examples/NetCore2/ConsoleExample/ConsoleExample.csproj @@ -1,10 +1,11 @@ - + PackageReference - + Exe netcoreapp2.0 + false diff --git a/examples/NetCore2/ConsoleExample/Program.cs b/examples/NetCore2/ConsoleExample/Program.cs index 5f4144ee..2b8fdecb 100644 --- a/examples/NetCore2/ConsoleExample/Program.cs +++ b/examples/NetCore2/ConsoleExample/Program.cs @@ -9,10 +9,11 @@ class Program { static void Main(string[] args) { - var logger = NLog.LogManager.LoadConfiguration("nlog.config").GetCurrentClassLogger(); + var logger = NLog.LogManager.GetCurrentClassLogger(); try { - using (var servicesProvider = BuildDi()) + var servicesProvider = BuildDi(); + using (servicesProvider as IDisposable) { var runner = servicesProvider.GetRequiredService(); runner.DoAction("Action1"); @@ -35,7 +36,7 @@ static void Main(string[] args) } - private static ServiceProvider BuildDi() + private static IServiceProvider BuildDi() { var services = new ServiceCollection(); diff --git a/examples/NetCore2/HostingExample/HostingExample.csproj b/examples/NetCore2/HostingExample/HostingExample.csproj new file mode 100644 index 00000000..8ea457af --- /dev/null +++ b/examples/NetCore2/HostingExample/HostingExample.csproj @@ -0,0 +1,26 @@ + + + + PackageReference + + Exe + netcoreapp2.0 + Latest + false + + + + + + + + + + + + + Always + + + + diff --git a/examples/NetCore2/HostingExample/NLog.xsd b/examples/NetCore2/HostingExample/NLog.xsd new file mode 100644 index 00000000..2f57d096 --- /dev/null +++ b/examples/NetCore2/HostingExample/NLog.xsd @@ -0,0 +1,3106 @@ + + + + + + + + + + + + + + + Watch config file for changes and reload automatically. + + + + + Print internal NLog messages to the console. Default value is: false + + + + + Print internal NLog messages to the console error output. Default value is: false + + + + + Write internal NLog messages to the specified file. + + + + + Log level threshold for internal log messages. Default value is: Info. + + + + + Global log level threshold for application log messages. Messages below this level won't be logged.. + + + + + Throw an exception when there is an internal error. Default value is: false. + + + + + Throw an exception when there is a configuration error. If not set, determined by throwExceptions. + + + + + Gets or sets a value indicating whether Variables should be kept on configuration reload. Default value is: false. + + + + + Write internal NLog messages to the System.Diagnostics.Trace. Default value is: false. + + + + + Write timestamps for internal NLog messages. Default value is: true. + + + + + Use InvariantCulture as default culture instead of CurrentCulture. Default value is: false. + + + + + Perform mesage template parsing and formatting of LogEvent messages (true = Always, false = Never, empty = Auto Detect). Default value is: empty. + + + + + + + + + + + + + + Make all targets within this section asynchronous (creates additional threads but the calling thread isn't blocked by any target writes). + + + + + + + + + + + + + + + + + Prefix for targets/layout renderers/filters/conditions loaded from this assembly. + + + + + Load NLog extensions from the specified file (*.dll) + + + + + Load NLog extensions from the specified assembly. Assembly name should be fully qualified. + + + + + + + + + + Name of the logger. May include '*' character which acts like a wildcard. Allowed forms are: *, Name, *Name, Name* and *Name* + + + + + Comma separated list of levels that this rule matches. + + + + + Minimum level that this rule matches. + + + + + Maximum level that this rule matches. + + + + + Level that this rule matches. + + + + + Comma separated list of target names. + + + + + Ignore further rules if this one matches. + + + + + Enable or disable logging rule. Disabled rules are ignored. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Name of the file to be included. You could use * wildcard. The name is relative to the name of the current config file. + + + + + Ignore any errors in the include file. + + + + + + + Variable name. + + + + + Variable value. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Name of the target. + + + + + Number of log events that should be processed in a batch by the lazy writer thread. + + + + + Limit of full s to write before yielding into Performance is better when writing many small batches, than writing a single large batch + + + + + Action to be taken when the lazy writer thread request queue count exceeds the set limit. + + + + + Limit on the number of requests in the lazy writer thread request queue. + + + + + Time in milliseconds to sleep between batches. + + + + + Target supports reuse of internal buffers, and doesn't have to constantly allocate new buffers Required for legacy NLog-targets, that expects buffers to remain stable after Write-method exit + + + + + + + + + + + + + + + + + + + + + + + + Name of the target. + + + + + Delay the flush until the LogEvent has been confirmed as written + + + + + Condition expression. Log events who meet this condition will cause a flush on the wrapped target. + + + + + Target supports reuse of internal buffers, and doesn't have to constantly allocate new buffers Required for legacy NLog-targets, that expects buffers to remain stable after Write-method exit + + + + + + + + + + + + + + + + + + + Name of the target. + + + + + Number of log events to be buffered. + + + + + Timeout (in milliseconds) after which the contents of buffer will be flushed if there's no write in the specified period of time. Use -1 to disable timed flushes. + + + + + Indicates whether to use sliding timeout. + + + + + Action to take if the buffer overflows. + + + + + Target supports reuse of internal buffers, and doesn't have to constantly allocate new buffers Required for legacy NLog-targets, that expects buffers to remain stable after Write-method exit + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Name of the target. + + + + + Encoding to be used. + + + + + Instance of that is used to format log messages. + + + + + End of line value if a newline is appended at the end of log message . + + + + + Maximum message size in bytes. + + + + + Indicates whether to append newline at the end of log message. + + + + + Action that should be taken if the will be more connections than . + + + + + Action that should be taken if the message is larger than maxMessageSize. + + + + + Maximum current connections. 0 = no maximum. + + + + + Indicates whether to keep connection open whenever possible. + + + + + Size of the connection cache (number of connections which are kept alive). + + + + + Network address. + + + + + Maximum queue size. + + + + + NDC item separator. + + + + + Indicates whether to include source info (file name and line number) in the information sent over the network. + + + + + Indicates whether to include dictionary contents. + + + + + Indicates whether to include contents of the stack. + + + + + Indicates whether to include stack contents. + + + + + Indicates whether to include dictionary contents. + + + + + Indicates whether to include call site (class and method name) in the information sent over the network. + + + + + Option to include all properties from the log events + + + + + AppInfo field. By default it's the friendly name of the current AppDomain. + + + + + Indicates whether to include NLog-specific extensions to log4j schema. + + + + + Target supports reuse of internal buffers, and doesn't have to constantly allocate new buffers Required for legacy NLog-targets, that expects buffers to remain stable after Write-method exit + + + + + + + + + + + + + + + + + + + + + + + + + + + Layout that should be use to calcuate the value for the parameter. + + + + + Viewer parameter name. + + + + + + + + + + + + + + + + + + + + + + Name of the target. + + + + + Text to be rendered. + + + + + Header. + + + + + Footer. + + + + + Indicates whether to use default row highlighting rules. + + + + + Indicates whether to auto-check if the console is available. - Disables console writing if Environment.UserInteractive = False (Windows Service) - Disables console writing if Console Standard Input is not available (Non-Console-App) + + + + + The encoding for writing messages to the . + + + + + Indicates whether the error stream (stderr) should be used instead of the output stream (stdout). + + + + + Target supports reuse of internal buffers, and doesn't have to constantly allocate new buffers Required for legacy NLog-targets, that expects buffers to remain stable after Write-method exit + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Condition that must be met in order to set the specified foreground and background color. + + + + + Background color. + + + + + Foreground color. + + + + + + + + + + + + + + + + Indicates whether to ignore case when comparing texts. + + + + + Regular expression to be matched. You must specify either text or regex. + + + + + Text to be matched. You must specify either text or regex. + + + + + Indicates whether to match whole words only. + + + + + Compile the ? This can improve the performance, but at the costs of more memory usage. If false, the Regex Cache is used. + + + + + Background color. + + + + + Foreground color. + + + + + + + + + + + + + + + + + + + Name of the target. + + + + + Text to be rendered. + + + + + Header. + + + + + Footer. + + + + + Indicates whether to send the log messages to the standard error instead of the standard output. + + + + + Indicates whether to auto-check if the console is available - Disables console writing if Environment.UserInteractive = False (Windows Service) - Disables console writing if Console Standard Input is not available (Non-Console-App) + + + + + The encoding for writing messages to the . + + + + + Target supports reuse of internal buffers, and doesn't have to constantly allocate new buffers Required for legacy NLog-targets, that expects buffers to remain stable after Write-method exit + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Name of the target. + + + + + Obsolete - value will be ignored! The logging code always runs outside of transaction. Gets or sets a value indicating whether to use database transactions. Some data providers require this. + + + + + Database user name. If the ConnectionString is not provided this value will be used to construct the "User ID=" part of the connection string. + + + + + Name of the database provider. + + + + + Database password. If the ConnectionString is not provided this value will be used to construct the "Password=" part of the connection string. + + + + + Indicates whether to keep the database connection open between the log events. + + + + + Database name. If the ConnectionString is not provided this value will be used to construct the "Database=" part of the connection string. + + + + + Name of the connection string (as specified in <connectionStrings> configuration section. + + + + + Connection string. When provided, it overrides the values specified in DBHost, DBUserName, DBPassword, DBDatabase. + + + + + Database host name. If the ConnectionString is not provided this value will be used to construct the "Server=" part of the connection string. + + + + + Connection string using for installation and uninstallation. If not provided, regular ConnectionString is being used. + + + + + Target supports reuse of internal buffers, and doesn't have to constantly allocate new buffers Required for legacy NLog-targets, that expects buffers to remain stable after Write-method exit + + + + + Text of the SQL command to be run on each log level. + + + + + Type of the SQL command to be run on each log level. + + + + + + + + + + + + + + + + + + + + + + + Type of the command. + + + + + Connection string to run the command against. If not provided, connection string from the target is used. + + + + + Indicates whether to ignore failures. + + + + + Command text. + + + + + + + + + + + + + + Layout that should be use to calcuate the value for the parameter. + + + + + Database parameter name. + + + + + Database parameter precision. + + + + + Database parameter scale. + + + + + Database parameter size. + + + + + + + + + + + + + + + + Name of the target. + + + + + Text to be rendered. + + + + + Header. + + + + + Footer. + + + + + Target supports reuse of internal buffers, and doesn't have to constantly allocate new buffers Required for legacy NLog-targets, that expects buffers to remain stable after Write-method exit + + + + + + + + + + + + + + + + Name of the target. + + + + + Layout used to format log messages. + + + + + Target supports reuse of internal buffers, and doesn't have to constantly allocate new buffers Required for legacy NLog-targets, that expects buffers to remain stable after Write-method exit + + + + + + + + + + + + + + + + + + + + + + + + + Name of the target. + + + + + Layout used to format log messages. + + + + + Layout that renders event Category. + + + + + Layout that renders event ID. + + + + + Name of the Event Log to write to. This can be System, Application or any user-defined name. + + + + + Name of the machine on which Event Log service is running. + + + + + Value to be used as the event Source. + + + + + Action to take if the message is larger than the option. + + + + + Optional entrytype. When not set, or when not convertable to then determined by + + + + + Maximum Event log size in kilobytes. If null, the value won't be set. Default is 512 Kilobytes as specified by Eventlog API + + + + + Message length limit to write to the Event Log. + + + + + Target supports reuse of internal buffers, and doesn't have to constantly allocate new buffers Required for legacy NLog-targets, that expects buffers to remain stable after Write-method exit + + + + + + + + + + + + + + + + + + + + + + + Name of the target. + + + + + Indicates whether to return to the first target after any successful write. + + + + + Target supports reuse of internal buffers, and doesn't have to constantly allocate new buffers Required for legacy NLog-targets, that expects buffers to remain stable after Write-method exit + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Name of the target. + + + + + Text to be rendered. + + + + + Header. + + + + + Footer. + + + + + File encoding. + + + + + Line ending mode. + + + + + Way file archives are numbered. + + + + + Name of the file to be used for an archive. + + + + + Indicates whether to automatically archive log files every time the specified time passes. + + + + + Size in bytes above which log files will be automatically archived. Warning: combining this with isn't supported. We cannot create multiple archive files, if they should have the same name. Choose: + + + + + Indicates whether to compress archive files into the zip archive format. + + + + + Maximum number of archive files that should be kept. + + + + + Gets or set a value indicating whether a managed file stream is forced, instead of using the native implementation. + + + + + Is the an absolute or relative path? + + + + + Cleanup invalid values in a filename, e.g. slashes in a filename. If set to true, this can impact the performance of massive writes. If set to false, nothing gets written when the filename is wrong. + + + + + Whether or not this target should just discard all data that its asked to write. Mostly used for when testing NLog Stack except final write + + + + + Is the an absolute or relative path? + + + + + Value indicationg whether file creation calls should be synchronized by a system global mutex. + + + + + Maximum number of log filenames that should be stored as existing. + + + + + Indicates whether the footer should be written only when the file is archived. + + + + + Name of the file to write to. + + + + + Value specifying the date format to use when archiving files. + + + + + Indicates whether to archive old log file on startup. + + + + + Indicates whether to create directories if they do not exist. + + + + + File attributes (Windows only). + + + + + Indicates whether to delete old log file on startup. + + + + + Indicates whether to replace file contents on each write instead of appending log message at the end. + + + + + Indicates whether to enable log file(s) to be deleted. + + + + + Number of times the write is appended on the file before NLog discards the log message. + + + + + Indicates whether concurrent writes to the log file by multiple processes on the same host. + + + + + Indicates whether to keep log file open instead of opening and closing it on each logging event. + + + + + Indicates whether concurrent writes to the log file by multiple processes on different network hosts. + + + + + Number of files to be kept open. Setting this to a higher value may improve performance in a situation where a single File target is writing to many files (such as splitting by level or by logger). + + + + + Maximum number of seconds that files are kept open. If this number is negative the files are not automatically closed after a period of inactivity. + + + + + Target supports reuse of internal buffers, and doesn't have to constantly allocate new buffers Required for legacy NLog-targets, that expects buffers to remain stable after Write-method exit + + + + + Log file buffer size in bytes. + + + + + Indicates whether to automatically flush the file buffers after each log message. + + + + + Delay in milliseconds to wait before attempting to write to the file again. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Name of the target. + + + + + Condition expression. Log events who meet this condition will be forwarded to the wrapped target. + + + + + Target supports reuse of internal buffers, and doesn't have to constantly allocate new buffers Required for legacy NLog-targets, that expects buffers to remain stable after Write-method exit + + + + + + + + + + + + + + + + + + + + + + Name of the target. + + + + + Windows domain name to change context to. + + + + + Required impersonation level. + + + + + Type of the logon provider. + + + + + Logon Type. + + + + + User account password. + + + + + Indicates whether to revert to the credentials of the process instead of impersonating another user. + + + + + Username to change context to. + + + + + Target supports reuse of internal buffers, and doesn't have to constantly allocate new buffers Required for legacy NLog-targets, that expects buffers to remain stable after Write-method exit + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Name of the target. + + + + + Interval in which messages will be written up to the number of messages. + + + + + Maximum allowed number of messages written per . + + + + + Target supports reuse of internal buffers, and doesn't have to constantly allocate new buffers Required for legacy NLog-targets, that expects buffers to remain stable after Write-method exit + + + + + + + + + + + + + + + + + + + + + + Name of the target. + + + + + Endpoint address. + + + + + Name of the endpoint configuration in WCF configuration file. + + + + + Indicates whether to use a WCF service contract that is one way (fire and forget) or two way (request-reply) + + + + + Client ID. + + + + + Indicates whether to include per-event properties in the payload sent to the server. + + + + + Indicates whether to use binary message encoding. + + + + + Target supports reuse of internal buffers, and doesn't have to constantly allocate new buffers Required for legacy NLog-targets, that expects buffers to remain stable after Write-method exit + + + + + + + + + + + + + + + + Layout that should be use to calculate the value for the parameter. + + + + + Name of the parameter. + + + + + Type of the parameter. + + + + + Type of the parameter. Obsolete alias for + + + + + Parameter can combine multiple LogEvents into a single parameter value + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Name of the target. + + + + + Text to be rendered. + + + + + Header. + + + + + Footer. + + + + + Indicates whether to send message as HTML instead of plain text. + + + + + Encoding to be used for sending e-mail. + + + + + Indicates whether to add new lines between log entries. + + + + + CC email addresses separated by semicolons (e.g. john@domain.com;jane@domain.com). + + + + + Recipients' email addresses separated by semicolons (e.g. john@domain.com;jane@domain.com). + + + + + BCC email addresses separated by semicolons (e.g. john@domain.com;jane@domain.com). + + + + + Mail message body (repeated for each log message send in one mail). + + + + + Mail subject. + + + + + Sender's email address (e.g. joe@domain.com). + + + + + Indicates the SMTP client timeout. + + + + + Priority used for sending mails. + + + + + Indicates whether NewLine characters in the body should be replaced with tags. + + + + + Target supports reuse of internal buffers, and doesn't have to constantly allocate new buffers Required for legacy NLog-targets, that expects buffers to remain stable after Write-method exit + + + + + SMTP Server to be used for sending. + + + + + SMTP Authentication mode. + + + + + Username used to connect to SMTP server (used when SmtpAuthentication is set to "basic"). + + + + + Password used to authenticate against SMTP server (used when SmtpAuthentication is set to "basic"). + + + + + Indicates whether SSL (secure sockets layer) should be used when communicating with SMTP server. + + + + + Port number that SMTP Server is listening on. + + + + + Indicates whether the default Settings from System.Net.MailSettings should be used. + + + + + Folder where applications save mail messages to be processed by the local SMTP server. + + + + + Specifies how outgoing email messages will be handled. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Name of the target. + + + + + Layout used to format log messages. + + + + + Target supports reuse of internal buffers, and doesn't have to constantly allocate new buffers Required for legacy NLog-targets, that expects buffers to remain stable after Write-method exit + + + + + + + + + + + + + + + + + + Name of the target. + + + + + Class name. + + + + + Method name. The method must be public and static. Use the AssemblyQualifiedName , https://msdn.microsoft.com/en-us/library/system.type.assemblyqualifiedname(v=vs.110).aspx e.g. + + + + + Target supports reuse of internal buffers, and doesn't have to constantly allocate new buffers Required for legacy NLog-targets, that expects buffers to remain stable after Write-method exit + + + + + + + + + + + + + + + + + + + + + + + + + + + Name of the target. + + + + + Layout used to format log messages. + + + + + Encoding to be used. + + + + + End of line value if a newline is appended at the end of log message . + + + + + Maximum message size in bytes. + + + + + Indicates whether to append newline at the end of log message. + + + + + Action that should be taken if the will be more connections than . + + + + + Action that should be taken if the message is larger than maxMessageSize. + + + + + Network address. + + + + + Size of the connection cache (number of connections which are kept alive). + + + + + Indicates whether to keep connection open whenever possible. + + + + + Maximum current connections. 0 = no maximum. + + + + + Maximum queue size. + + + + + Target supports reuse of internal buffers, and doesn't have to constantly allocate new buffers Required for legacy NLog-targets, that expects buffers to remain stable after Write-method exit + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Name of the target. + + + + + Encoding to be used. + + + + + Instance of that is used to format log messages. + + + + + End of line value if a newline is appended at the end of log message . + + + + + Maximum message size in bytes. + + + + + Indicates whether to append newline at the end of log message. + + + + + Action that should be taken if the will be more connections than . + + + + + Action that should be taken if the message is larger than maxMessageSize. + + + + + Maximum current connections. 0 = no maximum. + + + + + Indicates whether to keep connection open whenever possible. + + + + + Size of the connection cache (number of connections which are kept alive). + + + + + Network address. + + + + + Maximum queue size. + + + + + NDC item separator. + + + + + Indicates whether to include source info (file name and line number) in the information sent over the network. + + + + + Indicates whether to include dictionary contents. + + + + + Indicates whether to include contents of the stack. + + + + + Indicates whether to include stack contents. + + + + + Indicates whether to include dictionary contents. + + + + + Indicates whether to include call site (class and method name) in the information sent over the network. + + + + + Option to include all properties from the log events + + + + + AppInfo field. By default it's the friendly name of the current AppDomain. + + + + + Indicates whether to include NLog-specific extensions to log4j schema. + + + + + Target supports reuse of internal buffers, and doesn't have to constantly allocate new buffers Required for legacy NLog-targets, that expects buffers to remain stable after Write-method exit + + + + + + + + + + + + + + + + + Name of the target. + + + + + Layout used to format log messages. + + + + + Indicates whether to perform layout calculation. + + + + + Target supports reuse of internal buffers, and doesn't have to constantly allocate new buffers Required for legacy NLog-targets, that expects buffers to remain stable after Write-method exit + + + + + + + + + + + + + + + + Name of the target. + + + + + Layout used to format log messages. + + + + + Target supports reuse of internal buffers, and doesn't have to constantly allocate new buffers Required for legacy NLog-targets, that expects buffers to remain stable after Write-method exit + + + + + + + + + + + + + + + + + + + + + + Name of the target. + + + + + Indicates whether performance counter should be automatically created. + + + + + Name of the performance counter category. + + + + + Counter help text. + + + + + Name of the performance counter. + + + + + Performance counter type. + + + + + The value by which to increment the counter. + + + + + Performance counter instance name. + + + + + Target supports reuse of internal buffers, and doesn't have to constantly allocate new buffers Required for legacy NLog-targets, that expects buffers to remain stable after Write-method exit + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Name of the target. + + + + + Default filter to be applied when no specific rule matches. + + + + + Target supports reuse of internal buffers, and doesn't have to constantly allocate new buffers Required for legacy NLog-targets, that expects buffers to remain stable after Write-method exit + + + + + + + + + + + + + Condition to be tested. + + + + + Resulting filter to be applied when the condition matches. + + + + + + + + + + + + + Name of the target. + + + + + Target supports reuse of internal buffers, and doesn't have to constantly allocate new buffers Required for legacy NLog-targets, that expects buffers to remain stable after Write-method exit + + + + + + + + + + + + + + + + Name of the target. + + + + + Target supports reuse of internal buffers, and doesn't have to constantly allocate new buffers Required for legacy NLog-targets, that expects buffers to remain stable after Write-method exit + + + + + Number of times to repeat each log message. + + + + + + + + + + + + + + + + + Name of the target. + + + + + Target supports reuse of internal buffers, and doesn't have to constantly allocate new buffers Required for legacy NLog-targets, that expects buffers to remain stable after Write-method exit + + + + + Number of retries that should be attempted on the wrapped target in case of a failure. + + + + + Time to wait between retries in milliseconds. + + + + + + + + + + + + + + + Name of the target. + + + + + Target supports reuse of internal buffers, and doesn't have to constantly allocate new buffers Required for legacy NLog-targets, that expects buffers to remain stable after Write-method exit + + + + + + + + + + + + + + + Name of the target. + + + + + Target supports reuse of internal buffers, and doesn't have to constantly allocate new buffers Required for legacy NLog-targets, that expects buffers to remain stable after Write-method exit + + + + + + + + + + + + + + + + + Name of the target. + + + + + Layout used to format log messages. + + + + + Always use independent of + + + + + Target supports reuse of internal buffers, and doesn't have to constantly allocate new buffers Required for legacy NLog-targets, that expects buffers to remain stable after Write-method exit + + + + + + + + + + + + + + + + + + + + + + + + + + + + Name of the target. + + + + + Should we include the BOM (Byte-order-mark) for UTF? Influences the property. This will only work for UTF-8. + + + + + Target supports reuse of internal buffers, and doesn't have to constantly allocate new buffers Required for legacy NLog-targets, that expects buffers to remain stable after Write-method exit + + + + + Encoding. + + + + + Value whether escaping be done according to the old NLog style (Very non-standard) + + + + + Value whether escaping be done according to Rfc3986 (Supports Internationalized Resource Identifiers - IRIs) + + + + + Web service method name. Only used with Soap. + + + + + Web service namespace. Only used with Soap. + + + + + Indicates whether to pre-authenticate the HttpWebRequest (Requires 'Authorization' in parameters) + + + + + Protocol to be used when calling web service. + + + + + Web service URL. + + + + + Name of the root XML element, if POST of XML document chosen. If so, this property must not be null. (see and ). + + + + + (optional) root namespace of the XML document, if POST of XML document chosen. (see and ). + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Footer layout. + + + + + Header layout. + + + + + Body layout (can be repeated multiple times). + + + + + Custom column delimiter value (valid when ColumnDelimiter is set to 'Custom'). + + + + + Column delimiter. + + + + + Quote Character. + + + + + Quoting mode. + + + + + Indicates whether CVS should include header. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Layout of the column. + + + + + Name of the column. + + + + + + + + + + + + + + + + + + List of property names to exclude when is true + + + + + Option to include all properties from the log events + + + + + Indicates whether to include contents of the dictionary. + + + + + Indicates whether to include contents of the dictionary. + + + + + Option to render the empty object value {} + + + + + Option to suppress the extra spaces in the output json + + + + + + + + + + + + + + + Determines wether or not this attribute will be Json encoded. + + + + + Indicates whether to escape non-ascii characters + + + + + Layout that will be rendered as the attribute's value. + + + + + Name of the attribute. + + + + + + + + + + + + + + Footer layout. + + + + + Header layout. + + + + + Body layout (can be repeated multiple times). + + + + + + + + + + + + + + + + + + Option to include all properties from the log events + + + + + Indicates whether to include contents of the dictionary. + + + + + Indicates whether to include contents of the dictionary. + + + + + Indicates whether to include contents of the stack. + + + + + Indicates whether to include contents of the stack. + + + + + + + + + + + + + + Layout text. + + + + + + + + + + + + + + + Action to be taken when filter matches. + + + + + Condition expression. + + + + + + + + + + + + + + + + + + + + + + + + + + Action to be taken when filter matches. + + + + + Indicates whether to ignore case when comparing strings. + + + + + Layout to be used to filter log messages. + + + + + Substring to be matched. + + + + + + + + + + + + + + + + + Action to be taken when filter matches. + + + + + String to compare the layout to. + + + + + Indicates whether to ignore case when comparing strings. + + + + + Layout to be used to filter log messages. + + + + + + + + + + + + + + + + + Action to be taken when filter matches. + + + + + Indicates whether to ignore case when comparing strings. + + + + + Layout to be used to filter log messages. + + + + + Substring to be matched. + + + + + + + + + + + + + + + + + Action to be taken when filter matches. + + + + + String to compare the layout to. + + + + + Indicates whether to ignore case when comparing strings. + + + + + Layout to be used to filter log messages. + + + + + + + + + + + + + + + + + + + + + + + + Action to be taken when filter matches. + + + + + Layout to be used to filter log messages. + + + + + Default number of unique filter values to expect, will automatically increase if needed + + + + + Append FilterCount to the when an event is no longer filtered + + + + + Insert FilterCount value into when an event is no longer filtered + + + + + Applies the configured action to the initial logevent that starts the timeout period. Used to configure that it should ignore all events until timeout. + + + + + Max number of unique filter values to expect simultaneously + + + + + Max length of filter values, will truncate if above limit + + + + + Default buffer size for the internal buffers + + + + + Reuse internal buffers, and doesn't have to constantly allocate new buffers + + + + + How long before a filter expires, and logging is accepted again + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/examples/NetCore2/HostingExample/Program.cs b/examples/NetCore2/HostingExample/Program.cs new file mode 100644 index 00000000..140c60f9 --- /dev/null +++ b/examples/NetCore2/HostingExample/Program.cs @@ -0,0 +1,62 @@ +using System; +using System.Threading; +using System.Threading.Tasks; +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Hosting; +using Microsoft.Extensions.Logging; +using NLog.Extensions.Hosting; + +namespace HostingExample +{ + public class Program + { + static async Task Main(string[] args) + { + var logger = NLog.LogManager.GetCurrentClassLogger(); + try + { + var hostBuilder = new HostBuilder().UseNLog().ConfigureServices((hostContext, services) => + { + services.AddScoped(); + }); + await hostBuilder.RunConsoleAsync(); + Console.WriteLine("Press ANY key to exit"); + Console.ReadLine(); + } + catch (Exception ex) + { + //NLog: catch setup errors + logger.Error(ex, "Stopped program because of exception"); + throw; + } + finally + { + // Ensure to flush and stop internal timers/threads before application-exit (Avoid segmentation fault on Linux) + NLog.LogManager.Shutdown(); + } + } + + public class ConsoleHostedService : Microsoft.Extensions.Hosting.IHostedService + { + readonly ILogger _logger; + + public ConsoleHostedService(ILogger logger) + { + _logger = logger; + _logger.LogInformation("Created"); + } + + public async Task StartAsync(CancellationToken cancellationToken) + { + _logger.LogInformation("Started"); + await Task.Yield(); + } + + public async Task StopAsync(CancellationToken cancellationToken) + { + _logger.LogInformation("Stopped"); + await Task.Yield(); + } + } + } +} diff --git a/examples/NetCore2/HostingExample/nlog.config b/examples/NetCore2/HostingExample/nlog.config new file mode 100644 index 00000000..42c67950 --- /dev/null +++ b/examples/NetCore2/HostingExample/nlog.config @@ -0,0 +1,22 @@ + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/run-tests.ps1 b/run-tests.ps1 index c00e9e70..7591ad05 100644 --- a/run-tests.ps1 +++ b/run-tests.ps1 @@ -1,5 +1,8 @@ -dotnet restore test/NLog.Extensions.Logging.Tests.csproj -v minimal -dotnet build test/NLog.Extensions.Logging.Tests.csproj --configuration release -v minimal -dotnet test test/NLog.Extensions.Logging.Tests.csproj --configuration release +dotnet restore test/NLog.Extensions.Logging.Tests -v minimal +dotnet restore test/NLog.Extensions.Hosting.Tests -v minimal +dotnet build test/NLog.Extensions.Logging.Tests --configuration release -v minimal +dotnet build test/NLog.Extensions.Hosting.Tests --configuration release -v minimal +dotnet test test/NLog.Extensions.Logging.Tests --configuration release +dotnet test test/NLog.Extensions.Hosting.Tests --configuration release exit $LASTEXITCODE \ No newline at end of file diff --git a/src/NLog.Extensions.Hosting/Extensions/ConfigureExtensions.cs b/src/NLog.Extensions.Hosting/Extensions/ConfigureExtensions.cs new file mode 100644 index 00000000..f63cc9d4 --- /dev/null +++ b/src/NLog.Extensions.Hosting/Extensions/ConfigureExtensions.cs @@ -0,0 +1,50 @@ +using System; +using System.Reflection; +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Hosting; +using Microsoft.Extensions.Logging; +using NLog.Config; +using NLog.Extensions.Logging; + +namespace NLog.Extensions.Hosting +{ + /// + /// Helpers for IHostbuilder, netcore 2.1 + /// + public static class ConfigureExtensions + { + /// + /// Enable and configure NLog as a logging provider for buildable generic host (.NET Core 2.1+). + /// Can be used in discrete containers as well. + /// + /// + /// IHostBuilder for chaining + public static IHostBuilder UseNLog(this IHostBuilder builder) + { + if (builder == null) throw new ArgumentNullException(nameof(builder)); + return builder.UseNLog(null); + } + + /// + /// Enable and configure NLog as a logging provider for buildable generic host (.NET Core 2.1+). + /// Can be used in discrete containers as well. + /// + /// + /// NLogProviderOptions object to configure NLog behavior + /// IHostBuilder for chaining + public static IHostBuilder UseNLog(this IHostBuilder builder, NLogProviderOptions options) + { + if (builder == null) throw new ArgumentNullException(nameof(builder)); + + builder.ConfigureServices((hostbuilder, services) => + { + ConfigurationItemFactory.Default.RegisterItemsFromAssembly(typeof(ConfigureExtensions).GetTypeInfo() + .Assembly); + + services.AddSingleton(new LoggerFactory().AddNLog(options)); + }); + + return builder; + } + } +} \ No newline at end of file diff --git a/src/NLog.Extensions.Hosting/NLog.Extensions.Hosting.csproj b/src/NLog.Extensions.Hosting/NLog.Extensions.Hosting.csproj new file mode 100644 index 00000000..9abceedf --- /dev/null +++ b/src/NLog.Extensions.Hosting/NLog.Extensions.Hosting.csproj @@ -0,0 +1,40 @@ + + + + netstandard2.0 + full + true + true + true + + NLog.Extensions.Hosting v$(ProductVersion) + $(ProductVersion) + + NLog + Julian Verdurmen;Bryan Gonzalez + NLog extension for Microsoft.Extensions.Hosting for usage in .NET Standard libraries and net core applications making use of the generic Host class introduced in netcore 2.1 + https://github.com/NLog/NLog.Extensions.Logging + https://github.com/NLog/NLog.Extensions.Logging/blob/master/LICENSE + https://nlog-project.org/NConfig.png + https://github.com/NLog/NLog.Extensions.Logging.git + git + NLog;Microsoft.Extensions.Hosting;log;logfiles;netcore + 1.0: Initial release + + + {548E65CE-0378-4812-AE00-B173F1251D3C} + true + 1.0.0.0 + ..\NLog.snk + true + + + + + + + + + + + diff --git a/src/NLog.Extensions.Hosting/Properties/AssemblyInfo.cs b/src/NLog.Extensions.Hosting/Properties/AssemblyInfo.cs new file mode 100644 index 00000000..7a0e8b24 --- /dev/null +++ b/src/NLog.Extensions.Hosting/Properties/AssemblyInfo.cs @@ -0,0 +1,6 @@ +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +[assembly: ComVisible(false)] + +[assembly: InternalsVisibleTo("NLog.Extensions.Hosting.Tests, PublicKey=0024000004800000940000000602000000240000525341310004000001000100772391E63C104728ADCF18E2390474262559FA7F34A4215848F43288CDE875DCC92A06222E9BE0592B211FF74ADBB5D21A7AAB5522B540B1735F2F03279221056FEDBE7E534073DABEE9DB48F8ECEBCF1DC98A95576E45CBEFF5FE7C4842859451AB2DAE7A8370F1B2F7A529D2CA210E3E844D973523D73D193DF6C17F1314A6")] \ No newline at end of file diff --git a/src/NLog.Extensions.Logging/Logging/NLogLoggerProvider.cs b/src/NLog.Extensions.Logging/Logging/NLogLoggerProvider.cs index 63da7623..d18e23dd 100644 --- a/src/NLog.Extensions.Logging/Logging/NLogLoggerProvider.cs +++ b/src/NLog.Extensions.Logging/Logging/NLogLoggerProvider.cs @@ -35,7 +35,7 @@ public NLogLoggerProvider() /// public NLogLoggerProvider(NLogProviderOptions options) { - Options = options; + Options = options ?? NLogProviderOptions.Default; _beginScopeParser = new NLogBeginScopeParser(options); RegisterHiddenAssembliesForCallSite(); } diff --git a/src/NLog.Extensions.Logging/NLog.Extensions.Logging.csproj b/src/NLog.Extensions.Logging/NLog.Extensions.Logging.csproj index f2b2af4b..941852c5 100644 --- a/src/NLog.Extensions.Logging/NLog.Extensions.Logging.csproj +++ b/src/NLog.Extensions.Logging/NLog.Extensions.Logging.csproj @@ -3,11 +3,14 @@ PackageReference net451;net461;netstandard1.3;netstandard1.5;netstandard2.0 + full + true true true - + NLog.Extensions.Logging v$(ProductVersion) $(ProductVersion) + Microsoft;Julian Verdurmen NLog NLog provider for Microsoft.Extensions.Logging for usage in .NET Standard libraries and console applicaties. @@ -24,15 +27,16 @@ For ASP.NET Core, use NLog.Web.AspNetCore: https://www.nuget.org/packages/NLog.W Full changelog: https://github.com/NLog/NLog.Extensions.Logging/blob/master/CHANGELOG.MD - https://nlog-project.org/NConfig.png https://github.com/NLog/NLog.Extensions.Logging https://github.com/NLog/NLog.Extensions.Logging/blob/master/LICENSE - git + https://nlog-project.org/NConfig.png https://github.com/NLog/NLog.Extensions.Logging.git + git + {6A236D76-C9D9-4B1D-8DDE-F6978D110288} true 1.0.0.0 - NLog.snk + ..\NLog.snk true @@ -84,11 +88,4 @@ Full changelog: https://github.com/NLog/NLog.Extensions.Logging/blob/master/CHAN $(Title) - - - - - full - true - diff --git a/src/NLog.Extensions.Logging/Properties/AssemblyInfo.cs b/src/NLog.Extensions.Logging/Properties/AssemblyInfo.cs index c776dd19..7fc34c73 100644 --- a/src/NLog.Extensions.Logging/Properties/AssemblyInfo.cs +++ b/src/NLog.Extensions.Logging/Properties/AssemblyInfo.cs @@ -1,4 +1,6 @@ using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; -[assembly: InternalsVisibleTo("NLog.Extensions.Logging.Tests, PublicKey=0024000004800000940000000602000000240000525341310004000001000100772391E63C104728ADCF18E2390474262559FA7F34A4215848F43288CDE875DCC92A06222E9BE0592B211FF74ADBB5D21A7AAB5522B540B1735F2F03279221056FEDBE7E534073DABEE9DB48F8ECEBCF1DC98A95576E45CBEFF5FE7C4842859451AB2DAE7A8370F1B2F7A529D2CA210E3E844D973523D73D193DF6C17F1314A6")] +[assembly: ComVisible(false)] +[assembly: InternalsVisibleTo("NLog.Extensions.Logging.Tests, PublicKey=0024000004800000940000000602000000240000525341310004000001000100772391E63C104728ADCF18E2390474262559FA7F34A4215848F43288CDE875DCC92A06222E9BE0592B211FF74ADBB5D21A7AAB5522B540B1735F2F03279221056FEDBE7E534073DABEE9DB48F8ECEBCF1DC98A95576E45CBEFF5FE7C4842859451AB2DAE7A8370F1B2F7A529D2CA210E3E844D973523D73D193DF6C17F1314A6")] \ No newline at end of file diff --git a/src/NLog.Extensions.Logging/NLog.snk b/src/NLog.snk similarity index 100% rename from src/NLog.Extensions.Logging/NLog.snk rename to src/NLog.snk diff --git a/test/NLog.Extensions.Hosting.Tests/ExtensionMethodTests.cs b/test/NLog.Extensions.Hosting.Tests/ExtensionMethodTests.cs new file mode 100644 index 00000000..29d7074c --- /dev/null +++ b/test/NLog.Extensions.Hosting.Tests/ExtensionMethodTests.cs @@ -0,0 +1,34 @@ +using System.Linq; +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Hosting; +using Microsoft.Extensions.Logging; +using NLog.Extensions.Logging; +using Xunit; + +namespace NLog.Extensions.Hosting.Tests +{ + public class ExtensionMethodTests + { + [Fact] + public void UseNLog_noParams_buildsAndExposesValidIServiceCollectiont() + { + var actual = new HostBuilder().UseNLog().Build(); + var serviceCount = actual.Services.GetServices().Count(); + + Assert.NotNull(actual); + Assert.Equal(2, serviceCount); + } + + [Fact] + public void UseNLog_withOptionsParam_buildsAndExposesValidIServiceCollection() + { + var someParam = new NLogProviderOptions {CaptureMessageProperties = false, CaptureMessageTemplates = false}; + + var actual = new HostBuilder().UseNLog(someParam).Build(); + var serviceCount = actual.Services.GetServices().Count(); + + Assert.NotNull(actual); + Assert.Equal(2, serviceCount); + } + } +} \ No newline at end of file diff --git a/test/NLog.Extensions.Hosting.Tests/NLog.Extensions.Hosting.Tests.csproj b/test/NLog.Extensions.Hosting.Tests/NLog.Extensions.Hosting.Tests.csproj new file mode 100644 index 00000000..5c1b89aa --- /dev/null +++ b/test/NLog.Extensions.Hosting.Tests/NLog.Extensions.Hosting.Tests.csproj @@ -0,0 +1,31 @@ + + + PackageReference + + netcoreapp2.0 + Library + false + full + true + + true + false + ..\..\src\NLog.snk + true + + + + + + + + + + + + + + Always + + + \ No newline at end of file diff --git a/test/NLog.Extensions.Hosting.Tests/Properties/AssemblyInfo.cs b/test/NLog.Extensions.Hosting.Tests/Properties/AssemblyInfo.cs new file mode 100644 index 00000000..4a0154fc --- /dev/null +++ b/test/NLog.Extensions.Hosting.Tests/Properties/AssemblyInfo.cs @@ -0,0 +1,6 @@ +using System.Reflection; +using System.Runtime.InteropServices; + +[assembly: ComVisible(false)] + +[assembly: Guid("a47d764d-c167-4bf2-bc60-d0d01eba9742")] diff --git a/test/CustomBeginScopeTest.cs b/test/NLog.Extensions.Logging.Tests/CustomBeginScopeTest.cs similarity index 100% rename from test/CustomBeginScopeTest.cs rename to test/NLog.Extensions.Logging.Tests/CustomBeginScopeTest.cs diff --git a/test/CustomLoggerCallSiteTest.cs b/test/NLog.Extensions.Logging.Tests/CustomLoggerCallSiteTest.cs similarity index 99% rename from test/CustomLoggerCallSiteTest.cs rename to test/NLog.Extensions.Logging.Tests/CustomLoggerCallSiteTest.cs index 184f0cbc..98f452de 100644 --- a/test/CustomLoggerCallSiteTest.cs +++ b/test/NLog.Extensions.Logging.Tests/CustomLoggerCallSiteTest.cs @@ -68,6 +68,5 @@ public void SayHello() _logger.LogInformation("Hello"); } } - } } diff --git a/test/CustomLoggerPropertyTest.cs b/test/NLog.Extensions.Logging.Tests/CustomLoggerPropertyTest.cs similarity index 100% rename from test/CustomLoggerPropertyTest.cs rename to test/NLog.Extensions.Logging.Tests/CustomLoggerPropertyTest.cs diff --git a/test/LoggerTests.cs b/test/NLog.Extensions.Logging.Tests/LoggerTests.cs similarity index 100% rename from test/LoggerTests.cs rename to test/NLog.Extensions.Logging.Tests/LoggerTests.cs diff --git a/test/NLog.Extensions.Logging.Tests.csproj b/test/NLog.Extensions.Logging.Tests/NLog.Extensions.Logging.Tests.csproj similarity index 85% rename from test/NLog.Extensions.Logging.Tests.csproj rename to test/NLog.Extensions.Logging.Tests/NLog.Extensions.Logging.Tests.csproj index f60e3fd8..895408ea 100644 --- a/test/NLog.Extensions.Logging.Tests.csproj +++ b/test/NLog.Extensions.Logging.Tests/NLog.Extensions.Logging.Tests.csproj @@ -4,20 +4,19 @@ PackageReference netcoreapp1.1;netcoreapp2.0;net452;net461 + Library + false + full + true true false - NLog.snk + ..\..\src\NLog.snk true - - full - true - - - + @@ -33,7 +32,7 @@ - + diff --git a/test/NLogMessageParameterListTests.cs b/test/NLog.Extensions.Logging.Tests/NLogMessageParameterListTests.cs similarity index 99% rename from test/NLogMessageParameterListTests.cs rename to test/NLog.Extensions.Logging.Tests/NLogMessageParameterListTests.cs index 0c964606..66e0ee6e 100644 --- a/test/NLogMessageParameterListTests.cs +++ b/test/NLog.Extensions.Logging.Tests/NLogMessageParameterListTests.cs @@ -58,6 +58,5 @@ public void CreateNLogMessageParameterDifferentCaptureTypes() Assert.Equal(new MessageTemplateParameter("b", 2, null, CaptureType.Stringify), list[1]); Assert.Equal(new MessageTemplateParameter("c", 3, null, CaptureType.Serialize), list[2]); } - } } diff --git a/test/NLogTestBase.cs b/test/NLog.Extensions.Logging.Tests/NLogTestBase.cs similarity index 100% rename from test/NLogTestBase.cs rename to test/NLog.Extensions.Logging.Tests/NLogTestBase.cs diff --git a/test/Properties/AssemblyInfo-test.cs b/test/NLog.Extensions.Logging.Tests/Properties/AssemblyInfo.cs similarity index 100% rename from test/Properties/AssemblyInfo-test.cs rename to test/NLog.Extensions.Logging.Tests/Properties/AssemblyInfo.cs diff --git a/test/nlog.config b/test/NLog.Extensions.Logging.Tests/nlog.config similarity index 100% rename from test/nlog.config rename to test/NLog.Extensions.Logging.Tests/nlog.config diff --git a/test/NLog.snk b/test/NLog.snk deleted file mode 100644 index ae6cb7d0..00000000 Binary files a/test/NLog.snk and /dev/null differ