diff --git a/.gitignore b/.gitignore index bc52de5..e7d9000 100644 --- a/.gitignore +++ b/.gitignore @@ -129,7 +129,7 @@ publish/ # Publish Web Output *.[Pp]ublish.xml *.azurePubxml -# TODO: Comment the next line if you want to checkin your web deploy settings +# TODO: Comment the next line if you want to checkin your web deploy settings # but database connection strings (with potential passwords) will be unencrypted *.pubxml *.publishproj @@ -196,3 +196,6 @@ FakesAssemblies/ *.opt *.orig project.lock.json + +# JetBrains Rider +.idea diff --git a/Build.ps1 b/Build.ps1 index 7c5a85f..41fbf5d 100644 --- a/Build.ps1 +++ b/Build.ps1 @@ -20,7 +20,12 @@ foreach ($src in ls src/*) { echo "build: Packaging project in $src" - & dotnet pack -c Release -o ..\..\artifacts --version-suffix=$suffix + if($suffix) { + & dotnet pack -c Release --include-source -o ..\..\artifacts --version-suffix=$suffix + } else { + & dotnet pack -c Release --include-source -o ..\..\artifacts + } + if($LASTEXITCODE -ne 0) { exit 1 } Pop-Location diff --git a/appveyor.yml b/appveyor.yml index 078620b..2a0d6a6 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -1,13 +1,13 @@ version: '{build}' skip_tags: true -image: Visual Studio 2015 +image: Visual Studio 2017 Preview configuration: Release install: - ps: mkdir -Force ".\build\" | Out-Null - - ps: Invoke-WebRequest "https://raw.githubusercontent.com/dotnet/cli/rel/1.0.0-preview2/scripts/obtain/dotnet-install.ps1" -OutFile ".\build\installcli.ps1" - - ps: $env:DOTNET_INSTALL_DIR = "$pwd\.dotnetcli" - - ps: '& .\build\installcli.ps1 -InstallDir "$env:DOTNET_INSTALL_DIR" -NoPath -Version 1.0.0-preview2-003121' - - ps: $env:Path = "$env:DOTNET_INSTALL_DIR;$env:Path" + #- ps: Invoke-WebRequest "https://raw.githubusercontent.com/dotnet/cli/release/2.0.0/scripts/obtain/dotnet-install.ps1" -OutFile ".\build\installcli.ps1" + #- ps: $env:DOTNET_INSTALL_DIR = "$pwd\.dotnetcli" + #- ps: '& .\build\installcli.ps1 -InstallDir "$env:DOTNET_INSTALL_DIR" -NoPath -Version 2.0.0-preview2-006497' + #- ps: $env:Path = "$env:DOTNET_INSTALL_DIR;$env:Path" build_script: - ps: ./Build.ps1 test: off @@ -27,4 +27,4 @@ deploy: tag: v$(appveyor_build_version) on: branch: master - + diff --git a/global.json b/global.json index a2b2a41..73bdd84 100644 --- a/global.json +++ b/global.json @@ -1,6 +1,5 @@ { - "projects": [ "src", "test" ], "sdk": { - "version": "1.0.0-preview2-003121" + "version": "2.0.0-preview2-006497" } } diff --git a/samples/Sample/Program.cs b/samples/Sample/Program.cs index 22eabef..7f95bfa 100644 --- a/samples/Sample/Program.cs +++ b/samples/Sample/Program.cs @@ -1,10 +1,11 @@ using System; +using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; using Serilog; namespace Sample { - public static class Program + public class Program { public static void Main(string[] args) { @@ -13,18 +14,22 @@ public static void Main(string[] args) .WriteTo.LiterateConsole() .CreateLogger(); - var logger = new LoggerFactory() - .AddSerilog() - .CreateLogger(typeof(Program).FullName); + var services = new ServiceCollection() + .AddLogging(builder => + { + builder.AddSerilog(); + }); - logger.LogInformation("Starting"); + var serviceProvider = services.BuildServiceProvider(); + // getting the logger using the class's name is conventional + var logger = serviceProvider.GetRequiredService>(); var startTime = DateTimeOffset.UtcNow; logger.LogInformation(1, "Started at {StartTime} and 0x{Hello:X} is hex of 42", startTime, 42); try { - throw new Exception("Boom"); + throw new Exception("Boom!"); } catch (Exception ex) { diff --git a/samples/Sample/Sample.csproj b/samples/Sample/Sample.csproj new file mode 100644 index 0000000..5c34526 --- /dev/null +++ b/samples/Sample/Sample.csproj @@ -0,0 +1,20 @@ + + + + net461;netcoreapp2.0 + Sample + Exe + Sample + + + + + + + + + + + + + \ No newline at end of file diff --git a/samples/Sample/Sample.xproj b/samples/Sample/Sample.xproj deleted file mode 100644 index 632d81f..0000000 --- a/samples/Sample/Sample.xproj +++ /dev/null @@ -1,15 +0,0 @@ - - - - 14.0 - $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion) - - - - 65357fbc-9bc4-466d-b621-1c3a19bc2a78 - Sample - .\obj - .\bin\ - - - \ No newline at end of file diff --git a/samples/Sample/project.json b/samples/Sample/project.json deleted file mode 100644 index 03cc49a..0000000 --- a/samples/Sample/project.json +++ /dev/null @@ -1,27 +0,0 @@ -{ - "buildOptions": { - "emitEntryPoint": true - }, - "dependencies": { - "Serilog.Extensions.Logging": { "target": "project" }, - "Serilog.Sinks.Literate": "2.0.0", - "Microsoft.Extensions.Logging": "1.0.0" - }, - - "frameworks": { - "net4.6": {}, - "netcoreapp1.0": { - "define": [ "ASYNCLOCAL" ], - "dependencies": { - "Microsoft.NETCore.App": { - "type": "platform", - "version": "1.0.0" - } - }, - "imports": [ - "dnxcore50", - "portable-net45+win8" - ] - } - } -} diff --git a/samples/WebSample/Startup.cs b/samples/WebSample/Startup.cs index df76f4a..4d6c493 100644 --- a/samples/WebSample/Startup.cs +++ b/samples/WebSample/Startup.cs @@ -32,6 +32,12 @@ public Startup(IHostingEnvironment env) // This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { + services.AddLogging(builder => + { + // Specifying dispose: true closes and flushes the Serilog `Log` class when the app shuts down. + builder.AddSerilog(dispose: true); + }); + // Add framework services. services.AddMvc(); } @@ -39,9 +45,6 @@ public void ConfigureServices(IServiceCollection services) // This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory) { - // Specifying dispose: true closes and flushes the Serilog `Log` class when the app shuts down. - loggerFactory.AddSerilog(dispose: true); - if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); diff --git a/samples/WebSample/WebSample.csproj b/samples/WebSample/WebSample.csproj new file mode 100644 index 0000000..9fa8d95 --- /dev/null +++ b/samples/WebSample/WebSample.csproj @@ -0,0 +1,41 @@ + + + netcoreapp2.0 + true + WebSample + Exe + + + + PreserveNewest + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/samples/WebSample/WebSample.xproj b/samples/WebSample/WebSample.xproj deleted file mode 100644 index 94a8514..0000000 --- a/samples/WebSample/WebSample.xproj +++ /dev/null @@ -1,23 +0,0 @@ - - - - 14.0 - $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion) - - - - 486df7eb-128d-4c79-8b97-9cefeaddb948 - WebSample - .\obj - .\bin\ - v4.5.2 - - - 2.0 - - - - - - - diff --git a/samples/WebSample/project.json b/samples/WebSample/project.json deleted file mode 100644 index 4ad7c34..0000000 --- a/samples/WebSample/project.json +++ /dev/null @@ -1,70 +0,0 @@ -{ - "dependencies": { - "Microsoft.NETCore.App": { - "version": "1.0.0", - "type": "platform" - }, - "Microsoft.AspNetCore.Diagnostics": "1.0.0", - "Microsoft.AspNetCore.Mvc": "1.0.0", - "Microsoft.AspNetCore.Razor.Tools": { - "version": "1.0.0-preview2-final", - "type": "build" - }, - "Microsoft.AspNetCore.Server.IISIntegration": "1.0.0", - "Microsoft.AspNetCore.Server.Kestrel": "1.0.0", - "Microsoft.AspNetCore.StaticFiles": "1.0.0", - "Microsoft.Extensions.Configuration.EnvironmentVariables": "1.0.0", - "Microsoft.Extensions.Configuration.Json": "1.0.0", - "Microsoft.Extensions.Logging": "1.0.0", - "Microsoft.Extensions.Logging.Console": "1.0.0", - "Microsoft.Extensions.Logging.Debug": "1.0.0", - "Microsoft.Extensions.Options.ConfigurationExtensions": "1.0.0", - "Microsoft.VisualStudio.Web.BrowserLink.Loader": "14.0.0", - "Serilog.Extensions.Logging": { "target": "project" }, - "Serilog.Settings.Configuration": "2.1.0-dev-00028", - "Serilog.Sinks.Trace": "2.0.0", - "Serilog.Sinks.Literate": "2.0.0", - "Serilog.Sinks.Seq": "3.1.1" - }, - - "tools": { - "BundlerMinifier.Core": "2.0.238", - "Microsoft.AspNetCore.Razor.Tools": "1.0.0-preview2-final", - "Microsoft.AspNetCore.Server.IISIntegration.Tools": "1.0.0-preview2-final" - }, - - "frameworks": { - "netcoreapp1.0": { - "imports": [ - "dotnet5.6", - "portable-net45+win8" - ] - } - }, - - "buildOptions": { - "emitEntryPoint": true, - "preserveCompilationContext": true - }, - - "runtimeOptions": { - "configProperties": { - "System.GC.Server": true - } - }, - - "publishOptions": { - "include": [ - "wwwroot", - "Views", - "Areas/**/Views", - "appsettings.json", - "web.config" - ] - }, - - "scripts": { - "prepublish": [ "bower install", "dotnet bundle" ], - "postpublish": [ "dotnet publish-iis --publish-folder %publish:OutputPath% --framework %publish:FullTargetFramework%" ] - } -} diff --git a/serilog-extensions-logging.sln b/serilog-extensions-logging.sln index 89d90ba..6282b71 100644 --- a/serilog-extensions-logging.sln +++ b/serilog-extensions-logging.sln @@ -1,30 +1,30 @@  Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio 14 -VisualStudioVersion = 14.0.25420.1 +# Visual Studio 15 +VisualStudioVersion = 15.0.26114.2 MinimumVisualStudioVersion = 10.0.40219.1 Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{A1893BD1-333D-4DFE-A0F0-DDBB2FE526E0}" EndProject -Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Serilog.Extensions.Logging", "src\Serilog.Extensions.Logging\Serilog.Extensions.Logging.xproj", "{903CD13A-D54B-4CEC-A55F-E22AE3D93B3B}" +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Serilog.Extensions.Logging", "src\Serilog.Extensions.Logging\Serilog.Extensions.Logging.csproj", "{903CD13A-D54B-4CEC-A55F-E22AE3D93B3B}" EndProject -Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Serilog.Extensions.Logging.Tests", "test\Serilog.Extensions.Logging.Tests\Serilog.Extensions.Logging.Tests.xproj", "{37EADF84-5E41-4224-A194-1E3299DCD0B8}" +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Serilog.Extensions.Logging.Tests", "test\Serilog.Extensions.Logging.Tests\Serilog.Extensions.Logging.Tests.csproj", "{37EADF84-5E41-4224-A194-1E3299DCD0B8}" EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "test", "test", "{E30F638E-BBBE-4AD1-93CE-48CC69CFEFE1}" EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "samples", "samples", "{F2407211-6043-439C-8E06-3641634332E7}" EndProject -Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Sample", "samples\Sample\Sample.xproj", "{65357FBC-9BC4-466D-B621-1C3A19BC2A78}" +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Sample", "samples\Sample\Sample.csproj", "{65357FBC-9BC4-466D-B621-1C3A19BC2A78}" EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "assets", "assets", "{9C21B9DF-AEDD-4AA6-BEA4-912DEF3E5B8E}" ProjectSection(SolutionItems) = preProject appveyor.yml = appveyor.yml Build.ps1 = Build.ps1 - global.json = global.json README.md = README.md assets\Serilog.snk = assets\Serilog.snk + global.json = global.json EndProjectSection EndProject -Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "WebSample", "samples\WebSample\WebSample.xproj", "{486DF7EB-128D-4C79-8B97-9CEFEADDB948}" +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WebSample", "samples\WebSample\WebSample.csproj", "{486DF7EB-128D-4C79-8B97-9CEFEADDB948}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution diff --git a/src/Serilog.Extensions.Logging/Extensions/Logging/SerilogLogger.cs b/src/Serilog.Extensions.Logging/Extensions/Logging/SerilogLogger.cs index e87a1cf..5dff16c 100644 --- a/src/Serilog.Extensions.Logging/Extensions/Logging/SerilogLogger.cs +++ b/src/Serilog.Extensions.Logging/Extensions/Logging/SerilogLogger.cs @@ -97,12 +97,20 @@ public void Log(LogLevel logLevel, EventId eventId, TState state, Except if (messageTemplate == null) { - var propertyName = state != null ? "State" : - (formatter != null ? "Message" : null); + string propertyName = null; + if (state != null) + { + propertyName = "State"; + messageTemplate = "{State:l}"; + } + else if (formatter != null) + { + propertyName = "Message"; + messageTemplate = "{Message:l}"; + } if (propertyName != null) { - messageTemplate = $"{{{propertyName}:l}}"; LogEventProperty property; if (logger.BindProperty(propertyName, AsLoggableValue(state, formatter), false, out property)) properties.Add(property); diff --git a/src/Serilog.Extensions.Logging/Properties/AssemblyInfo.cs b/src/Serilog.Extensions.Logging/Properties/AssemblyInfo.cs index f65e7fa..37885a5 100644 --- a/src/Serilog.Extensions.Logging/Properties/AssemblyInfo.cs +++ b/src/Serilog.Extensions.Logging/Properties/AssemblyInfo.cs @@ -1,7 +1,7 @@ using System.Reflection; using System.Runtime.CompilerServices; -[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyVersion("2.0.0.0")] [assembly: InternalsVisibleTo("Serilog.Extensions.Logging.Tests, PublicKey=" + "0024000004800000940000000602000000240000525341310004000001000100fb8d13fd344a1c" + diff --git a/src/Serilog.Extensions.Logging/Serilog.Extensions.Logging.csproj b/src/Serilog.Extensions.Logging/Serilog.Extensions.Logging.csproj new file mode 100644 index 0000000..c9d3bfb --- /dev/null +++ b/src/Serilog.Extensions.Logging/Serilog.Extensions.Logging.csproj @@ -0,0 +1,53 @@ + + + + Serilog provider for Microsoft.Extensions.Logging + 2.0.0 + Microsoft;Serilog Contributors + net45;net46;net461;netstandard1.3;netstandard2.0 + true + true + Serilog.Extensions.Logging + ../../assets/Serilog.snk + true + true + Serilog.Extensions.Logging + serilog;Microsoft.Extensions.Logging + http://serilog.net/images/serilog-extension-nuget.png + https://github.com/serilog/serilog-extensions-logging + http://www.apache.org/licenses/LICENSE-2.0 + false + + + + + + + + + + + + + + + + + + + $(DefineConstants);ASYNCLOCAL + + + + $(DefineConstants);ASYNCLOCAL + + + + $(DefineConstants);ASYNCLOCAL + + + + $(DefineConstants);ASYNCLOCAL + + + diff --git a/src/Serilog.Extensions.Logging/Serilog.Extensions.Logging.xproj b/src/Serilog.Extensions.Logging/Serilog.Extensions.Logging.xproj deleted file mode 100644 index f2134c4..0000000 --- a/src/Serilog.Extensions.Logging/Serilog.Extensions.Logging.xproj +++ /dev/null @@ -1,18 +0,0 @@ - - - - 14.0 - $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion) - - - - 903cd13a-d54b-4cec-a55f-e22ae3d93b3b - Serilog - .\obj - .\bin\ - - - 2.0 - - - \ No newline at end of file diff --git a/src/Serilog.Extensions.Logging/SerilogLoggerFactoryExtensions.cs b/src/Serilog.Extensions.Logging/SerilogLoggerFactoryExtensions.cs index b104322..c2aa06d 100644 --- a/src/Serilog.Extensions.Logging/SerilogLoggerFactoryExtensions.cs +++ b/src/Serilog.Extensions.Logging/SerilogLoggerFactoryExtensions.cs @@ -4,7 +4,6 @@ using System; using Microsoft.Extensions.Logging; using Serilog.Extensions.Logging; -using System.ComponentModel; namespace Serilog { @@ -13,21 +12,6 @@ namespace Serilog /// public static class SerilogLoggerFactoryExtensions { - /// - /// Add Serilog to the logging pipeline. - /// - /// The logger factory to configure. - /// The Serilog logger; if not supplied, the static will be used. - /// The logger factory. - [EditorBrowsable(EditorBrowsableState.Never)] - public static ILoggerFactory AddSerilog( - this ILoggerFactory factory, - ILogger logger) - { - if (factory == null) throw new ArgumentNullException(nameof(factory)); - return factory.AddSerilog(logger, false); - } - /// /// Add Serilog to the logging pipeline. /// diff --git a/src/Serilog.Extensions.Logging/SerilogLoggingBuilderExtensions.cs b/src/Serilog.Extensions.Logging/SerilogLoggingBuilderExtensions.cs new file mode 100644 index 0000000..d4538eb --- /dev/null +++ b/src/Serilog.Extensions.Logging/SerilogLoggingBuilderExtensions.cs @@ -0,0 +1,30 @@ +using System; +using Microsoft.Extensions.Logging; +using Serilog.Extensions.Logging; + +namespace Serilog +{ + /// + /// Extends with Serilog configuration methods. + /// + public static class SerilogLoggingBuilderExtensions + { + /// + /// Add Serilog to the logging pipeline. + /// + /// The to add logging provider to. + /// The Serilog logger; if not supplied, the static will be used. + /// When true, dispose when the framework disposes the provider. If the + /// logger is not specified but is true, the method will be + /// called on the static class instead. + /// The logger factory. + public static ILoggingBuilder AddSerilog(this ILoggingBuilder builder, ILogger logger = null, bool dispose = false) + { + if (builder == null) throw new ArgumentNullException(nameof(builder)); + + builder.AddProvider(new SerilogLoggerProvider(logger, dispose)); + + return builder; + } + } +} diff --git a/src/Serilog.Extensions.Logging/project.json b/src/Serilog.Extensions.Logging/project.json deleted file mode 100644 index 86322f2..0000000 --- a/src/Serilog.Extensions.Logging/project.json +++ /dev/null @@ -1,36 +0,0 @@ -{ - "version": "1.4.0-*", - "description": "Serilog provider for Microsoft.Extensions.Logging", - "authors": [ "Microsoft", "Serilog Contributors" ], - "packOptions": { - "tags": [ "serilog", "Microsoft.Extensions.Logging" ], - "projectUrl": "https://github.com/serilog/serilog-extensions-logging", - "licenseUrl": "http://www.apache.org/licenses/LICENSE-2.0", - "iconUrl": "http://serilog.net/images/serilog-extension-nuget.png" - }, - "dependencies": { - "Microsoft.Extensions.Logging.Abstractions": "1.0.0", - "Serilog": "2.3.0" - }, - "buildOptions": { - "keyFile": "../../assets/Serilog.snk", - "xmlDoc": true, - "warningsAsErrors": true - }, - "frameworks": { - "net4.5": { - "frameworkAssemblies": { "System.Runtime": { "type": "build" } } - }, - "net4.6": { - "frameworkAssemblies": { "System.Runtime": { "type": "build" } }, - "buildOptions": { - "define": [ "ASYNCLOCAL" ] - } - }, - "netstandard1.3": { - "buildOptions": { - "define": ["ASYNCLOCAL"] - } - } - } -} diff --git a/test/Serilog.Extensions.Logging.Tests/Serilog.Extensions.Logging.Tests.csproj b/test/Serilog.Extensions.Logging.Tests/Serilog.Extensions.Logging.Tests.csproj new file mode 100644 index 0000000..54eee14 --- /dev/null +++ b/test/Serilog.Extensions.Logging.Tests/Serilog.Extensions.Logging.Tests.csproj @@ -0,0 +1,30 @@ + + + + netcoreapp1.1;netcoreapp2.0;net46;net461 + Serilog.Extensions.Logging.Tests + ../../assets/Serilog.snk + true + true + Serilog.Extensions.Logging.Tests + true + $(PackageTargetFallback);dnxcore50;portable-net45+win8 + 1.0.4 + + + + + + + + + + + + + + + + + + diff --git a/test/Serilog.Extensions.Logging.Tests/Serilog.Extensions.Logging.Tests.xproj b/test/Serilog.Extensions.Logging.Tests/Serilog.Extensions.Logging.Tests.xproj deleted file mode 100644 index f9259c1..0000000 --- a/test/Serilog.Extensions.Logging.Tests/Serilog.Extensions.Logging.Tests.xproj +++ /dev/null @@ -1,18 +0,0 @@ - - - - 14.0 - $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion) - - - - 37eadf84-5e41-4224-a194-1e3299dcd0b8 - Serilog.Framework.Logging.Tests - .\obj - .\bin\ - - - 2.0 - - - \ No newline at end of file diff --git a/test/Serilog.Extensions.Logging.Tests/project.json b/test/Serilog.Extensions.Logging.Tests/project.json deleted file mode 100644 index 320de26..0000000 --- a/test/Serilog.Extensions.Logging.Tests/project.json +++ /dev/null @@ -1,27 +0,0 @@ -{ - "testRunner": "xunit", - "dependencies": { - "Serilog.Extensions.Logging": { "target": "project" }, - "xunit": "2.1.0", - "dotnet-test-xunit": "1.0.0-rc2-build10025" - }, - "buildOptions": { - "keyFile": "../../assets/Serilog.snk" - }, - "frameworks": { - "netcoreapp1.0": { - "dependencies": { - "Microsoft.NETCore.App": { - "type": "platform", - "version": "1.0.0" - } - }, - "imports": [ - "dnxcore50", - "portable-net45+win8" - ] - }, - "net4.6": {} - } -} -