Skip to content

Commit 8ed7d97

Browse files
authored
Merge pull request #91 from serilog/dev
2.0.0 Release
2 parents d9e9994 + 7bda6f2 commit 8ed7d97

23 files changed

+227
-280
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

Build.ps1

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,12 @@ foreach ($src in ls src/*) {
2020

2121
echo "build: Packaging project in $src"
2222

23-
& dotnet pack -c Release -o ..\..\artifacts --version-suffix=$suffix
23+
if($suffix) {
24+
& dotnet pack -c Release --include-source -o ..\..\artifacts --version-suffix=$suffix
25+
} else {
26+
& dotnet pack -c Release --include-source -o ..\..\artifacts
27+
}
28+
2429
if($LASTEXITCODE -ne 0) { exit 1 }
2530

2631
Pop-Location

appveyor.yml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
version: '{build}'
22
skip_tags: true
3-
image: Visual Studio 2015
3+
image: Visual Studio 2017 Preview
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-preview2/scripts/obtain/dotnet-install.ps1" -OutFile ".\build\installcli.ps1"
8-
- ps: $env:DOTNET_INSTALL_DIR = "$pwd\.dotnetcli"
9-
- ps: '& .\build\installcli.ps1 -InstallDir "$env:DOTNET_INSTALL_DIR" -NoPath -Version 1.0.0-preview2-003121'
10-
- ps: $env:Path = "$env:DOTNET_INSTALL_DIR;$env:Path"
7+
#- ps: Invoke-WebRequest "https://raw.githubusercontent.com/dotnet/cli/release/2.0.0/scripts/obtain/dotnet-install.ps1" -OutFile ".\build\installcli.ps1"
8+
#- ps: $env:DOTNET_INSTALL_DIR = "$pwd\.dotnetcli"
9+
#- ps: '& .\build\installcli.ps1 -InstallDir "$env:DOTNET_INSTALL_DIR" -NoPath -Version 2.0.0-preview2-006497'
10+
#- ps: $env:Path = "$env:DOTNET_INSTALL_DIR;$env:Path"
1111
build_script:
1212
- ps: ./Build.ps1
1313
test: off
@@ -27,4 +27,4 @@ deploy:
2727
tag: v$(appveyor_build_version)
2828
on:
2929
branch: master
30-
30+

global.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
{
2-
"projects": [ "src", "test" ],
32
"sdk": {
4-
"version": "1.0.0-preview2-003121"
3+
"version": "2.0.0-preview2-006497"
54
}
65
}

samples/Sample/Program.cs

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
using System;
2+
using Microsoft.Extensions.DependencyInjection;
23
using Microsoft.Extensions.Logging;
34
using Serilog;
45

56
namespace Sample
67
{
7-
public static class Program
8+
public class Program
89
{
910
public static void Main(string[] args)
1011
{
@@ -13,18 +14,22 @@ public static void Main(string[] args)
1314
.WriteTo.LiterateConsole()
1415
.CreateLogger();
1516

16-
var logger = new LoggerFactory()
17-
.AddSerilog()
18-
.CreateLogger(typeof(Program).FullName);
17+
var services = new ServiceCollection()
18+
.AddLogging(builder =>
19+
{
20+
builder.AddSerilog();
21+
});
1922

20-
logger.LogInformation("Starting");
23+
var serviceProvider = services.BuildServiceProvider();
24+
// getting the logger using the class's name is conventional
25+
var logger = serviceProvider.GetRequiredService<ILogger<Program>>();
2126

2227
var startTime = DateTimeOffset.UtcNow;
2328
logger.LogInformation(1, "Started at {StartTime} and 0x{Hello:X} is hex of 42", startTime, 42);
2429

2530
try
2631
{
27-
throw new Exception("Boom");
32+
throw new Exception("Boom!");
2833
}
2934
catch (Exception ex)
3035
{

samples/Sample/Sample.csproj

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<TargetFrameworks>net461;netcoreapp2.0</TargetFrameworks>
5+
<AssemblyName>Sample</AssemblyName>
6+
<OutputType>Exe</OutputType>
7+
<PackageId>Sample</PackageId>
8+
</PropertyGroup>
9+
10+
<ItemGroup>
11+
<ProjectReference Include="..\..\src\Serilog.Extensions.Logging\Serilog.Extensions.Logging.csproj" />
12+
</ItemGroup>
13+
14+
<ItemGroup>
15+
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="2.0.0" />
16+
<PackageReference Include="Microsoft.Extensions.Logging" Version="2.0.0" />
17+
<PackageReference Include="Serilog.Sinks.Literate" Version="2.0.0" />
18+
</ItemGroup>
19+
20+
</Project>

samples/Sample/Sample.xproj

Lines changed: 0 additions & 15 deletions
This file was deleted.

samples/Sample/project.json

Lines changed: 0 additions & 27 deletions
This file was deleted.

samples/WebSample/Startup.cs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,16 +32,19 @@ public Startup(IHostingEnvironment env)
3232
// This method gets called by the runtime. Use this method to add services to the container.
3333
public void ConfigureServices(IServiceCollection services)
3434
{
35+
services.AddLogging(builder =>
36+
{
37+
// Specifying dispose: true closes and flushes the Serilog `Log` class when the app shuts down.
38+
builder.AddSerilog(dispose: true);
39+
});
40+
3541
// Add framework services.
3642
services.AddMvc();
3743
}
3844

3945
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
4046
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
4147
{
42-
// Specifying dispose: true closes and flushes the Serilog `Log` class when the app shuts down.
43-
loggerFactory.AddSerilog(dispose: true);
44-
4548
if (env.IsDevelopment())
4649
{
4750
app.UseDeveloperExceptionPage();

samples/WebSample/WebSample.csproj

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<Project Sdk="Microsoft.NET.Sdk.Web">
2+
<PropertyGroup>
3+
<TargetFramework>netcoreapp2.0</TargetFramework>
4+
<PreserveCompilationContext>true</PreserveCompilationContext>
5+
<AssemblyName>WebSample</AssemblyName>
6+
<OutputType>Exe</OutputType>
7+
</PropertyGroup>
8+
<ItemGroup>
9+
<None Update="wwwroot\**\*;Views\**\*;Areas\**\Views">
10+
<CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory>
11+
</None>
12+
</ItemGroup>
13+
<ItemGroup>
14+
<ProjectReference Include="..\..\src\Serilog.Extensions.Logging\Serilog.Extensions.Logging.csproj" />
15+
</ItemGroup>
16+
<ItemGroup>
17+
<PackageReference Include="Microsoft.AspNetCore.Diagnostics" Version="1.0.2" />
18+
<PackageReference Include="Microsoft.AspNetCore.Mvc" Version="1.0.3" />
19+
<PackageReference Include="Microsoft.AspNetCore.Server.IISIntegration" Version="1.0.2" />
20+
<PackageReference Include="Microsoft.AspNetCore.Server.Kestrel" Version="1.0.3" />
21+
<PackageReference Include="Microsoft.AspNetCore.StaticFiles" Version="1.0.2" />
22+
<PackageReference Include="Microsoft.Extensions.Configuration.EnvironmentVariables" Version="1.0.2" />
23+
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="1.0.2" />
24+
<PackageReference Include="Microsoft.Extensions.Logging" Version="2.0.0" />
25+
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="1.0.2" />
26+
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="1.0.2" />
27+
<PackageReference Include="Microsoft.Extensions.Options.ConfigurationExtensions" Version="1.0.2" />
28+
<PackageReference Include="Microsoft.VisualStudio.Web.BrowserLink" Version="1.0.1" />
29+
<PackageReference Include="Serilog.Settings.Configuration" Version="2.3.1" />
30+
<PackageReference Include="Serilog.Sinks.Trace" Version="2.1.0" />
31+
<PackageReference Include="Serilog.Sinks.Literate" Version="2.1.0" />
32+
<PackageReference Include="Serilog.Sinks.Seq" Version="3.2.0" />
33+
</ItemGroup>
34+
<Target Name="PrepublishScript" BeforeTargets="PrepareForPublish">
35+
<Exec Command="bower install" />
36+
<Exec Command="dotnet bundle" />
37+
</Target>
38+
<ItemGroup>
39+
<DotNetCliToolReference Include="BundlerMinifier.Core" Version="2.2.301" />
40+
</ItemGroup>
41+
</Project>

samples/WebSample/WebSample.xproj

Lines changed: 0 additions & 23 deletions
This file was deleted.

samples/WebSample/project.json

Lines changed: 0 additions & 70 deletions
This file was deleted.

serilog-extensions-logging.sln

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,30 @@
11

22
Microsoft Visual Studio Solution File, Format Version 12.00
3-
# Visual Studio 14
4-
VisualStudioVersion = 14.0.25420.1
3+
# Visual Studio 15
4+
VisualStudioVersion = 15.0.26114.2
55
MinimumVisualStudioVersion = 10.0.40219.1
66
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{A1893BD1-333D-4DFE-A0F0-DDBB2FE526E0}"
77
EndProject
8-
Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Serilog.Extensions.Logging", "src\Serilog.Extensions.Logging\Serilog.Extensions.Logging.xproj", "{903CD13A-D54B-4CEC-A55F-E22AE3D93B3B}"
8+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Serilog.Extensions.Logging", "src\Serilog.Extensions.Logging\Serilog.Extensions.Logging.csproj", "{903CD13A-D54B-4CEC-A55F-E22AE3D93B3B}"
99
EndProject
10-
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}"
10+
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}"
1111
EndProject
1212
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "test", "test", "{E30F638E-BBBE-4AD1-93CE-48CC69CFEFE1}"
1313
EndProject
1414
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "samples", "samples", "{F2407211-6043-439C-8E06-3641634332E7}"
1515
EndProject
16-
Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Sample", "samples\Sample\Sample.xproj", "{65357FBC-9BC4-466D-B621-1C3A19BC2A78}"
16+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Sample", "samples\Sample\Sample.csproj", "{65357FBC-9BC4-466D-B621-1C3A19BC2A78}"
1717
EndProject
1818
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "assets", "assets", "{9C21B9DF-AEDD-4AA6-BEA4-912DEF3E5B8E}"
1919
ProjectSection(SolutionItems) = preProject
2020
appveyor.yml = appveyor.yml
2121
Build.ps1 = Build.ps1
22-
global.json = global.json
2322
README.md = README.md
2423
assets\Serilog.snk = assets\Serilog.snk
24+
global.json = global.json
2525
EndProjectSection
2626
EndProject
27-
Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "WebSample", "samples\WebSample\WebSample.xproj", "{486DF7EB-128D-4C79-8B97-9CEFEADDB948}"
27+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WebSample", "samples\WebSample\WebSample.csproj", "{486DF7EB-128D-4C79-8B97-9CEFEADDB948}"
2828
EndProject
2929
Global
3030
GlobalSection(SolutionConfigurationPlatforms) = preSolution

src/Serilog.Extensions.Logging/Extensions/Logging/SerilogLogger.cs

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -97,12 +97,20 @@ public void Log<TState>(LogLevel logLevel, EventId eventId, TState state, Except
9797

9898
if (messageTemplate == null)
9999
{
100-
var propertyName = state != null ? "State" :
101-
(formatter != null ? "Message" : null);
100+
string propertyName = null;
101+
if (state != null)
102+
{
103+
propertyName = "State";
104+
messageTemplate = "{State:l}";
105+
}
106+
else if (formatter != null)
107+
{
108+
propertyName = "Message";
109+
messageTemplate = "{Message:l}";
110+
}
102111

103112
if (propertyName != null)
104113
{
105-
messageTemplate = $"{{{propertyName}:l}}";
106114
LogEventProperty property;
107115
if (logger.BindProperty(propertyName, AsLoggableValue(state, formatter), false, out property))
108116
properties.Add(property);

0 commit comments

Comments
 (0)