Skip to content

Commit 6fddfe0

Browse files
authored
Merge pull request #27 from serilog/dev
Release 2.1
2 parents 0d86412 + ff3cbd7 commit 6fddfe0

10 files changed

+113
-130
lines changed

Diff for: appveyor.yml

+3-6
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,10 @@
11
version: '{build}'
22
skip_tags: true
3-
image: Visual Studio 2015
3+
image: Visual Studio 2017
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+
118
build_script:
129
- ps: ./Build.ps1
1310
test: off
@@ -16,7 +13,7 @@ artifacts:
1613
deploy:
1714
- provider: NuGet
1815
api_key:
19-
secure: nvZ/z+pMS91b3kG4DgfES5AcmwwGoBYQxr9kp4XiJHj25SAlgdIxFx++1N0lFH2x
16+
secure: bd9z4P73oltOXudAjPehwp9iDKsPtC+HbgshOrSgoyQKr5xVK+bxJQngrDJkHdY8
2017
skip_symbols: true
2118
on:
2219
branch: /^(master|dev)$/

Diff for: global.json

-6
This file was deleted.

Diff for: serilog-enrichers-environment.sln

+5-6
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,23 @@
11

22
Microsoft Visual Studio Solution File, Format Version 12.00
3-
# Visual Studio 14
4-
VisualStudioVersion = 14.0.25123.0
3+
# Visual Studio 15
4+
VisualStudioVersion = 15.0.26430.14
55
MinimumVisualStudioVersion = 10.0.40219.1
66
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{037440DE-440B-4129-9F7A-09B42D00397E}"
77
EndProject
88
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "assets", "assets", "{E9D1B5E1-DEB9-4A04-8BAB-24EC7240ADAF}"
99
ProjectSection(SolutionItems) = preProject
1010
Build.ps1 = Build.ps1
11-
global.json = global.json
1211
NuGet.Config = NuGet.Config
1312
README.md = README.md
1413
assets\Serilog.snk = assets\Serilog.snk
1514
EndProjectSection
1615
EndProject
17-
Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Serilog.Enrichers.Environment", "src\Serilog.Enrichers.Environment\Serilog.Enrichers.Environment.xproj", "{B884782D-6C07-4779-9074-D97F622799A9}"
18-
EndProject
1916
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "test", "test", "{406006F7-12FA-4A8A-ADC8-80E5338F5275}"
2017
EndProject
21-
Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Serilog.Enrichers.Environment.Tests", "test\Serilog.Enrichers.Environment.Tests\Serilog.Enrichers.Environment.Tests.xproj", "{3C2D8E01-5580-426A-BDD9-EC59CD98E618}"
18+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Serilog.Enrichers.Environment", "src\Serilog.Enrichers.Environment\Serilog.Enrichers.Environment.csproj", "{B884782D-6C07-4779-9074-D97F622799A9}"
19+
EndProject
20+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Serilog.Enrichers.Environment.Tests", "test\Serilog.Enrichers.Environment.Tests\Serilog.Enrichers.Environment.Tests.csproj", "{3C2D8E01-5580-426A-BDD9-EC59CD98E618}"
2221
EndProject
2322
Global
2423
GlobalSection(SolutionConfigurationPlatforms) = preSolution

Diff for: src/Serilog.Enrichers.Environment/Enrichers/MachineNameEnricher.cs

+28-12
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2013-2016 Serilog Contributors
1+
// Copyright 2013-2018 Serilog Contributors
22
//
33
// Licensed under the Apache License, Version 2.0 (the "License");
44
// you may not use this file except in compliance with the License.
@@ -11,12 +11,15 @@
1111
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
14-
1514

1615
using System;
1716
using Serilog.Core;
1817
using Serilog.Events;
19-
using System.Runtime.InteropServices;
18+
using System.Runtime.CompilerServices;
19+
20+
#if NETSTANDARD1_3
21+
using System.Net;
22+
#endif
2023

2124
namespace Serilog.Enrichers
2225
{
@@ -39,16 +42,29 @@ public class MachineNameEnricher : ILogEventEnricher
3942
/// <param name="propertyFactory">Factory for creating new properties to add to the event.</param>
4043
public void Enrich(LogEvent logEvent, ILogEventPropertyFactory propertyFactory)
4144
{
42-
#if ENV_USER_NAME
43-
_cachedProperty = _cachedProperty ?? propertyFactory.CreateProperty(MachineNamePropertyName, Environment.MachineName);
44-
#else
45-
var machineName = Environment.GetEnvironmentVariable("COMPUTERNAME");
46-
if (string.IsNullOrWhiteSpace(machineName))
47-
machineName = Environment.GetEnvironmentVariable("HOSTNAME");
45+
logEvent.AddPropertyIfAbsent(GetLogEventProperty(propertyFactory));
46+
}
47+
48+
private LogEventProperty GetLogEventProperty(ILogEventPropertyFactory propertyFactory)
49+
{
50+
// Don't care about thread-safety, in the worst case the field gets overwritten and one
51+
// property will be GCed
52+
if (_cachedProperty == null)
53+
_cachedProperty = CreateProperty(propertyFactory);
54+
55+
return _cachedProperty;
56+
}
4857

49-
_cachedProperty = _cachedProperty ?? propertyFactory.CreateProperty(MachineNamePropertyName, machineName);
58+
// Qualify as uncommon-path
59+
[MethodImpl(MethodImplOptions.NoInlining)]
60+
private static LogEventProperty CreateProperty(ILogEventPropertyFactory propertyFactory)
61+
{
62+
#if NETSTANDARD1_3
63+
var machineName = Dns.GetHostName();
64+
#else
65+
var machineName = Environment.MachineName;
5066
#endif
51-
logEvent.AddPropertyIfAbsent(_cachedProperty);
67+
return propertyFactory.CreateProperty(MachineNamePropertyName, machineName);
5268
}
5369
}
54-
}
70+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<Description>Enrich Serilog log events with properties from System.Environment.</Description>
5+
<VersionPrefix>2.1.3</VersionPrefix>
6+
<Authors>Serilog Contributors</Authors>
7+
<TargetFrameworks>net45;netstandard1.3;netstandard1.5</TargetFrameworks>
8+
<AssemblyName>Serilog.Enrichers.Environment</AssemblyName>
9+
<AssemblyOriginatorKeyFile>../../assets/Serilog.snk</AssemblyOriginatorKeyFile>
10+
<SignAssembly>true</SignAssembly>
11+
<PublicSign Condition=" '$(OS)' != 'Windows_NT' ">true</PublicSign>
12+
<PackageId>Serilog.Enrichers.Environment</PackageId>
13+
<PackageTags>serilog;machine;enricher</PackageTags>
14+
<PackageIconUrl>http://serilog.net/images/serilog-enricher-nuget.png</PackageIconUrl>
15+
<PackageProjectUrl>http://serilog.net</PackageProjectUrl>
16+
<PackageLicenseUrl>http://www.apache.org/licenses/LICENSE-2.0</PackageLicenseUrl>
17+
<RepositoryUrl>https://github.com/serilog/serilog-enrichers-environment</RepositoryUrl>
18+
<RepositoryType>git</RepositoryType>
19+
<GenerateAssemblyVersionAttribute>false</GenerateAssemblyVersionAttribute>
20+
</PropertyGroup>
21+
22+
<ItemGroup>
23+
<PackageReference Include="Serilog" Version="2.3.0" />
24+
</ItemGroup>
25+
26+
<ItemGroup Condition=" '$(TargetFramework)' == 'net45' ">
27+
<Reference Include="System" />
28+
<Reference Include="Microsoft.CSharp" />
29+
</ItemGroup>
30+
31+
<ItemGroup Condition=" '$(TargetFramework)' == 'netstandard1.3' ">
32+
<PackageReference Include="System.Net.NameResolution" Version="4.3.0" />
33+
</ItemGroup>
34+
35+
<PropertyGroup Condition=" '$(TargetFramework)' == 'net45' ">
36+
<DefineConstants>$(DefineConstants);ENV_USER_NAME</DefineConstants>
37+
</PropertyGroup>
38+
39+
</Project>

Diff for: src/Serilog.Enrichers.Environment/Serilog.Enrichers.Environment.xproj

-18
This file was deleted.

Diff for: src/Serilog.Enrichers.Environment/project.json

-33
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<TargetFrameworks>netcoreapp1.0;net46</TargetFrameworks>
5+
<AssemblyName>Serilog.Enrichers.Environment.Tests</AssemblyName>
6+
<AssemblyOriginatorKeyFile>../../assets/Serilog.snk</AssemblyOriginatorKeyFile>
7+
<SignAssembly>true</SignAssembly>
8+
<PublicSign Condition=" '$(OS)' != 'Windows_NT' ">true</PublicSign>
9+
<PackageId>Serilog.Enrichers.Environment.Tests</PackageId>
10+
<GenerateRuntimeConfigurationFiles>true</GenerateRuntimeConfigurationFiles>
11+
<PackageTargetFallback Condition=" '$(TargetFramework)' == 'netcoreapp1.0' ">$(PackageTargetFallback);dnxcore50;portable-net45+win8</PackageTargetFallback>
12+
<RuntimeFrameworkVersion Condition=" '$(TargetFramework)' == 'netcoreapp1.0' ">1.0.4</RuntimeFrameworkVersion>
13+
</PropertyGroup>
14+
15+
<ItemGroup>
16+
<None Include="App.config" />
17+
</ItemGroup>
18+
19+
<ItemGroup>
20+
<ProjectReference Include="..\..\src\Serilog.Enrichers.Environment\Serilog.Enrichers.Environment.csproj" />
21+
</ItemGroup>
22+
23+
<ItemGroup>
24+
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.0.0-preview-20170106-08" />
25+
<PackageReference Include="xunit.runner.visualstudio" Version="2.2.0-beta5-build1225" />
26+
<PackageReference Include="xunit" Version="2.2.0-beta5-build3474" />
27+
</ItemGroup>
28+
29+
<ItemGroup Condition=" '$(TargetFramework)' == 'net46' ">
30+
<Reference Include="System" />
31+
<Reference Include="Microsoft.CSharp" />
32+
</ItemGroup>
33+
34+
<ItemGroup>
35+
<Service Include="{82a7f48d-3b50-4b1e-b82e-3ada8210c358}" />
36+
</ItemGroup>
37+
38+
</Project>

Diff for: test/Serilog.Enrichers.Environment.Tests/Serilog.Enrichers.Environment.Tests.xproj

-21
This file was deleted.

Diff for: test/Serilog.Enrichers.Environment.Tests/project.json

-28
This file was deleted.

0 commit comments

Comments
 (0)