Skip to content

Commit 7a92b2f

Browse files
authored
Merge pull request #83 from gertjvr/dev
Adding netstandard 2.0 logging abstraction support
2 parents 11583f2 + 882b821 commit 7a92b2f

File tree

5 files changed

+65
-9
lines changed

5 files changed

+65
-9
lines changed

.gitignore

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ publish/
129129
# Publish Web Output
130130
*.[Pp]ublish.xml
131131
*.azurePubxml
132-
# TODO: Comment the next line if you want to checkin your web deploy settings
132+
# TODO: Comment the next line if you want to checkin your web deploy settings
133133
# but database connection strings (with potential passwords) will be unencrypted
134134
*.pubxml
135135
*.publishproj
@@ -196,3 +196,6 @@ FakesAssemblies/
196196
*.opt
197197
*.orig
198198
project.lock.json
199+
200+
# JetBrains Rider
201+
.idea

appveyor.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ image: Visual Studio 2015
44
configuration: Release
55
install:
66
- ps: mkdir -Force ".\build\" | Out-Null
7-
- ps: Invoke-WebRequest "https://raw.githubusercontent.com/dotnet/cli/rel/1.0.0/scripts/obtain/dotnet-install.ps1" -OutFile ".\build\installcli.ps1"
7+
- ps: Invoke-WebRequest "https://raw.githubusercontent.com/dotnet/cli/release/2.0.0-preview2/scripts/obtain/dotnet-install.ps1" -OutFile ".\build\installcli.ps1"
88
- ps: $env:DOTNET_INSTALL_DIR = "$pwd\.dotnetcli"
9-
- ps: '& .\build\installcli.ps1 -InstallDir "$env:DOTNET_INSTALL_DIR" -NoPath -Version 1.0.3'
9+
- ps: '& .\build\installcli.ps1 -InstallDir "$env:DOTNET_INSTALL_DIR" -NoPath -Version 2.0.0-preview2-006497'
1010
- ps: $env:Path = "$env:DOTNET_INSTALL_DIR;$env:Path"
1111
build_script:
1212
- ps: ./Build.ps1
@@ -27,4 +27,4 @@ deploy:
2727
tag: v$(appveyor_build_version)
2828
on:
2929
branch: master
30-
30+

global.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
22
"sdk": {
3-
"version": "1.0.3"
3+
"version": "2.0.0-preview2-006497"
44
}
5-
}
5+
}

src/Serilog.Extensions.Logging/Serilog.Extensions.Logging.csproj

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22

33
<PropertyGroup>
44
<Description>Serilog provider for Microsoft.Extensions.Logging</Description>
5-
<VersionPrefix>1.4.1</VersionPrefix>
5+
<VersionPrefix>2.0.0</VersionPrefix>
66
<Authors>Microsoft;Serilog Contributors</Authors>
7-
<TargetFrameworks>net45;net46;netstandard1.3</TargetFrameworks>
7+
<TargetFrameworks>net45;net46;netstandard1.3;netstandard2.0</TargetFrameworks>
88
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
99
<GenerateDocumentationFile>true</GenerateDocumentationFile>
1010
<AssemblyName>Serilog.Extensions.Logging</AssemblyName>
@@ -22,20 +22,36 @@
2222
</PropertyGroup>
2323

2424
<ItemGroup>
25-
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="1.0.0" />
2625
<PackageReference Include="Serilog" Version="2.3.0" />
2726
</ItemGroup>
2827

2928
<ItemGroup Condition=" '$(TargetFramework)' == 'net45' ">
3029
<Reference Include="System.Runtime" />
3130
<Reference Include="System" />
3231
<Reference Include="Microsoft.CSharp" />
32+
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="1.0.0" />
33+
<Compile Remove="SerilogLoggerServicesExtensions.cs" />
3334
</ItemGroup>
3435

3536
<ItemGroup Condition=" '$(TargetFramework)' == 'net46' ">
3637
<Reference Include="System.Runtime" />
3738
<Reference Include="System" />
3839
<Reference Include="Microsoft.CSharp" />
40+
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="1.0.0" />
41+
<Compile Remove="SerilogLoggerServicesExtensions.cs" />
42+
</ItemGroup>
43+
44+
<ItemGroup Condition=" '$(TargetFramework)' == 'netstandard1.3' ">
45+
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="1.0.0" />
46+
<Compile Remove="SerilogLoggerServicesExtensions.cs" />
47+
</ItemGroup>
48+
49+
<ItemGroup Condition=" '$(TargetFramework)' == 'netstandard2.0' ">
50+
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="2.0.0-preview2-final" />
51+
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="2.0.0-preview2-final" />
52+
<PackageReference Include="Microsoft.Extensions.Logging" Version="2.0.0-preview2-final" />
53+
<PackageReference Include="NETStandard.Library" Version="2.0.0-preview2-25401-01" />
54+
<Compile Remove="SerilogLoggerFactoryExtensions.cs" />
3955
</ItemGroup>
4056

4157
<PropertyGroup Condition=" '$(TargetFramework)' == 'net46' ">
@@ -46,4 +62,8 @@
4662
<DefineConstants>$(DefineConstants);ASYNCLOCAL</DefineConstants>
4763
</PropertyGroup>
4864

65+
<PropertyGroup Condition=" '$(TargetFramework)' == 'netstandard2.0' ">
66+
<DefineConstants>$(DefineConstants);ASYNCLOCAL</DefineConstants>
67+
</PropertyGroup>
68+
4969
</Project>
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
using System;
2+
using System.ComponentModel;
3+
using Microsoft.Extensions.DependencyInjection;
4+
using Microsoft.Extensions.Logging;
5+
using Serilog.Extensions.Logging;
6+
7+
8+
namespace Serilog
9+
{
10+
/// <summary>
11+
/// Extends <see cref="IServiceCollection"/> with Serilog configuration methods.
12+
/// </summary>
13+
public static class SerilogLoggerServicesExtensions
14+
{
15+
/// <summary>
16+
/// Add Serilog to the logging pipeline.
17+
/// </summary>
18+
/// <param name="services">The <see cref="T:Microsoft.Extensions.DependencyInjection.IServiceCollection" /> to add services to.</param>
19+
/// <param name="logger">The Serilog logger; if not supplied, the static <see cref="Serilog.Log"/> will be used.</param>
20+
/// <param name="dispose">When true, dispose <paramref name="logger"/> when the framework disposes the provider. If the
21+
/// logger is not specified but <paramref name="dispose"/> is true, the <see cref="Log.CloseAndFlush()"/> method will be
22+
/// called on the static <see cref="Log"/> class instead.</param>
23+
/// <returns>The logger factory.</returns>
24+
public static IServiceCollection AddSerilog(this IServiceCollection services, Serilog.ILogger logger = null, bool dispose = false)
25+
{
26+
if (services == null) throw new ArgumentNullException(nameof(services));
27+
28+
services.AddLogging(builder => builder.AddProvider(new SerilogLoggerProvider(logger, dispose)));
29+
30+
return services;
31+
}
32+
}
33+
}

0 commit comments

Comments
 (0)