Skip to content

Commit

Permalink
Merge pull request #18 from serilog/dev
Browse files Browse the repository at this point in the history
2.0.2 Release
  • Loading branch information
nblumhardt authored Aug 15, 2021
2 parents 80a9c16 + a4e3b54 commit 74f35ea
Show file tree
Hide file tree
Showing 17 changed files with 219 additions and 76 deletions.
2 changes: 1 addition & 1 deletion Build.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ foreach ($src in ls src/*) {

echo "build: Packaging project in $src"

& dotnet build -c Release --version-suffix=$buildSuffix
& dotnet build -c Release --version-suffix=$buildSuffix /p:ContinuousIntegrationBuild=true
& dotnet pack -c Release -o ..\..\artifacts --version-suffix=$suffix --no-build
if($LASTEXITCODE -ne 0) { exit 1 }

Expand Down
12 changes: 11 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

The process enricher for Serilog.

[![Build status](https://ci.appveyor.com/api/projects/status/ihq58voxyfwfanyg?svg=true)](https://ci.appveyor.com/project/serilog/serilog-enrichers-process) [![NuGet Version](http://img.shields.io/nuget/v/Serilog.Enrichers.Process.svg?style=flat)](https://www.nuget.org/packages/Serilog.Enricher.Process/)
[![Build status](https://ci.appveyor.com/api/projects/status/ihq58voxyfwfanyg?svg=true)](https://ci.appveyor.com/project/serilog/serilog-enrichers-process) [![NuGet Version](http://img.shields.io/nuget/v/Serilog.Enrichers.Process.svg?style=flat)](https://www.nuget.org/packages/Serilog.Enrichers.Process/)


To use the enricher, first install the NuGet package:
Expand All @@ -11,6 +11,16 @@ To use the enricher, first install the NuGet package:
Install-Package Serilog.Enrichers.Process
```

Then add `Enrich.WithProcessId()` and/or `.WithProcessName()` to the `LoggerConfiguration()`:

```csharp
Log.Logger = new LoggerConfiguration()
.WriteTo.Console()
.Enrich.WithProcessId()
.Enrich.WithProcessName()
.CreateLogger();
```

* [Documentation](https://github.com/serilog/serilog/wiki)

Copyright © 2016 Serilog Contributors - Provided under the [Apache License, Version 2.0](http://apache.org/licenses/LICENSE-2.0.html).
10 changes: 2 additions & 8 deletions appveyor.yml
Original file line number Diff line number Diff line change
@@ -1,13 +1,7 @@
version: '{build}'
skip_tags: true
image: Visual Studio 2015
image: Visual Studio 2019
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"
build_script:
- ps: ./Build.ps1
test: off
Expand All @@ -16,7 +10,7 @@ artifacts:
deploy:
- provider: NuGet
api_key:
secure: nvZ/z+pMS91b3kG4DgfES5AcmwwGoBYQxr9kp4XiJHj25SAlgdIxFx++1N0lFH2x
secure: 9B24CFy1l5KYjxsp8AXPx6ANkDI3KKXSqi18nCUk1kyj0mClwfNbNj0Tna4+gUC5
skip_symbols: true
on:
branch: /^(master|dev)$/
Expand Down
Binary file added assets/serilog-enricher-nuget.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 0 additions & 6 deletions global.json

This file was deleted.

29 changes: 20 additions & 9 deletions serilog-enrichers-process.sln
Original file line number Diff line number Diff line change
@@ -1,36 +1,47 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 14
VisualStudioVersion = 14.0.24720.0
# Visual Studio Version 16
VisualStudioVersion = 16.0.30608.117
MinimumVisualStudioVersion = 10.0.40219.1
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{037440DE-440B-4129-9F7A-09B42D00397E}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "assets", "assets", "{E9D1B5E1-DEB9-4A04-8BAB-24EC7240ADAF}"
ProjectSection(SolutionItems) = preProject
Build.ps1 = Build.ps1
global.json = global.json
NuGet.Config = NuGet.Config
README.md = README.md
assets\Serilog.snk = assets\Serilog.snk
EndProjectSection
EndProject
Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Serilog.Enrichers.Process", "src\Serilog.Enrichers.Process\Serilog.Enrichers.Process.xproj", "{2312A998-5E53-4355-9CB6-6014252B3E88}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Serilog.Enrichers.Process", "src\Serilog.Enrichers.Process\Serilog.Enrichers.Process.csproj", "{E950BED9-A953-4555-9159-B40ABDE7DC90}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Serilog.Enrichers.Process.Tests", "test\Serilog.Enrichers.Process.Tests\Serilog.Enrichers.Process.Tests.csproj", "{27336067-0A49-4053-9A57-76510C8D9097}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "tests", "tests", "{ACD52C07-EC24-4A6D-9DE4-653A6A89F74D}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{2312A998-5E53-4355-9CB6-6014252B3E88}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{2312A998-5E53-4355-9CB6-6014252B3E88}.Debug|Any CPU.Build.0 = Debug|Any CPU
{2312A998-5E53-4355-9CB6-6014252B3E88}.Release|Any CPU.ActiveCfg = Release|Any CPU
{2312A998-5E53-4355-9CB6-6014252B3E88}.Release|Any CPU.Build.0 = Release|Any CPU
{E950BED9-A953-4555-9159-B40ABDE7DC90}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{E950BED9-A953-4555-9159-B40ABDE7DC90}.Debug|Any CPU.Build.0 = Debug|Any CPU
{E950BED9-A953-4555-9159-B40ABDE7DC90}.Release|Any CPU.ActiveCfg = Release|Any CPU
{E950BED9-A953-4555-9159-B40ABDE7DC90}.Release|Any CPU.Build.0 = Release|Any CPU
{27336067-0A49-4053-9A57-76510C8D9097}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{27336067-0A49-4053-9A57-76510C8D9097}.Debug|Any CPU.Build.0 = Debug|Any CPU
{27336067-0A49-4053-9A57-76510C8D9097}.Release|Any CPU.ActiveCfg = Release|Any CPU
{27336067-0A49-4053-9A57-76510C8D9097}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{2312A998-5E53-4355-9CB6-6014252B3E88} = {037440DE-440B-4129-9F7A-09B42D00397E}
{E950BED9-A953-4555-9159-B40ABDE7DC90} = {037440DE-440B-4129-9F7A-09B42D00397E}
{27336067-0A49-4053-9A57-76510C8D9097} = {ACD52C07-EC24-4A6D-9DE4-653A6A89F74D}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {9BEC8B70-CA11-4400-AEAE-B0EAE15E933B}
EndGlobalSection
EndGlobal
10 changes: 9 additions & 1 deletion src/Serilog.Enrichers.Process/Enrichers/ProcessIdEnricher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,16 @@ public class ProcessIdEnricher : ILogEventEnricher
/// <param name="propertyFactory">Factory for creating new properties to add to the event.</param>
public void Enrich(LogEvent logEvent, ILogEventPropertyFactory propertyFactory)
{
_cachedProperty = _cachedProperty ?? propertyFactory.CreateProperty(ProcessIdPropertyName, System.Diagnostics.Process.GetCurrentProcess().Id);
_cachedProperty = _cachedProperty ?? propertyFactory.CreateProperty(ProcessIdPropertyName, GetProcessId());
logEvent.AddPropertyIfAbsent(_cachedProperty);
}

private static int GetProcessId()
{
using(var process = System.Diagnostics.Process.GetCurrentProcess())
{
return process.Id;
}
}
}
}
10 changes: 9 additions & 1 deletion src/Serilog.Enrichers.Process/Enrichers/ProcessNameEnricher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,16 @@ public class ProcessNameEnricher : ILogEventEnricher
/// <param name="propertyFactory">Factory for creating new properties to add to the event.</param>
public void Enrich(LogEvent logEvent, ILogEventPropertyFactory propertyFactory)
{
_cachedProperty = _cachedProperty ?? propertyFactory.CreateProperty(ProcessNamePropertyName, System.Diagnostics.Process.GetCurrentProcess().ProcessName);
_cachedProperty = _cachedProperty ?? propertyFactory.CreateProperty(ProcessNamePropertyName, GetProcessName());
logEvent.AddPropertyIfAbsent(_cachedProperty);
}

private static string GetProcessName()
{
using(var process = System.Diagnostics.Process.GetCurrentProcess())
{
return process.ProcessName;
}
}
}
}
49 changes: 49 additions & 0 deletions src/Serilog.Enrichers.Process/Serilog.Enrichers.Process.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<Description>The process enricher for Serilog.</Description>
<VersionPrefix>2.0.2</VersionPrefix>
<Authors>Serilog Contributors</Authors>
<TargetFrameworks>net45;netstandard1.3;netstandard2.0</TargetFrameworks>
<AssemblyName>Serilog.Enrichers.Process</AssemblyName>
<AssemblyOriginatorKeyFile>../../assets/Serilog.snk</AssemblyOriginatorKeyFile>
<SignAssembly>true</SignAssembly>
<PublicSign Condition=" '$(OS)' != 'Windows_NT' ">true</PublicSign>
<PackageId>Serilog.Enrichers.Process</PackageId>
<PackageTags>serilog;process;enricher</PackageTags>
<PackageIcon>serilog-enricher-nuget.png</PackageIcon>
<PackageProjectUrl>http://serilog.net</PackageProjectUrl>
<PackageLicenseExpression>Apache-2.0</PackageLicenseExpression>
<GenerateAssemblyVersionAttribute>false</GenerateAssemblyVersionAttribute>
<RepositoryUrl>https://github.com/serilog/serilog-enrichers-process</RepositoryUrl>
<RepositoryType>git</RepositoryType>
<PublishRepositoryUrl>true</PublishRepositoryUrl>
<AllowedOutputExtensionsInPackageBuildOutputFolder>$(AllowedOutputExtensionsInPackageBuildOutputFolder);.pdb</AllowedOutputExtensionsInPackageBuildOutputFolder>
<EmbedUntrackedSources>true</EmbedUntrackedSources>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.0.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Serilog" Version="2.3.0" />
</ItemGroup>

<ItemGroup Condition=" '$(TargetFramework)' == 'net45' ">
<Reference Include="System" />
<Reference Include="Microsoft.CSharp" />
</ItemGroup>

<ItemGroup Condition=" '$(TargetFramework)' == 'netstandard1.3' ">
<PackageReference Include="System.Diagnostics.Process" Version="4.1.0" />
</ItemGroup>

<ItemGroup>
<None Include="..\..\assets\serilog-enricher-nuget.png">
<Pack>True</Pack>
<PackagePath></PackagePath>
</None>
</ItemGroup>

</Project>
18 changes: 0 additions & 18 deletions src/Serilog.Enrichers.Process/Serilog.Enrichers.Process.xproj

This file was deleted.

31 changes: 0 additions & 31 deletions src/Serilog.Enrichers.Process/project.json

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
using Serilog.Events;
using Serilog.Tests.Support;
using Xunit;

namespace Serilog.Enrichers.Process.Tests
{
public class ProcessIdEnricherTests
{
[Fact]
public void ProcessIdEnricherIsApplied()
{
LogEvent evt = null;
var log = new LoggerConfiguration()
.Enrich.WithProcessId()
.WriteTo.Sink(new DelegatingSink(e => evt = e))
.CreateLogger();

log.Information(@"Has a ProcessId property");

Assert.NotNull(evt);

var processId = System.Diagnostics.Process.GetCurrentProcess().Id;
Assert.Equal(processId, (int)evt.Properties["ProcessId"].LiteralValue());
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
using Serilog.Events;
using Serilog.Tests.Support;
using Xunit;

namespace Serilog.Enrichers.Process.Tests
{
public class ProcessNameEnricherTests
{
[Fact]
public void ProcessNameEnricherIsApplied()
{
LogEvent evt = null;
var log = new LoggerConfiguration()
.Enrich.WithProcessName()
.WriteTo.Sink(new DelegatingSink(e => evt = e))
.CreateLogger();

log.Information(@"Has a ProcessName property");

Assert.NotNull(evt);

var processName = System.Diagnostics.Process.GetCurrentProcess().ProcessName;
Assert.Equal(processName, (string)evt.Properties["ProcessName"].LiteralValue());
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>netcoreapp3.1;netcoreapp2.1;net46</TargetFrameworks>
<IsPackable>false</IsPackable>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\..\src\Serilog.Enrichers.Process\Serilog.Enrichers.Process.csproj" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.7.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.3">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="xunit" Version="2.4.1" />
</ItemGroup>

</Project>
33 changes: 33 additions & 0 deletions test/Serilog.Enrichers.Process.Tests/Support/DelegatingSink.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
using System;
using Serilog.Core;
using Serilog.Events;

namespace Serilog.Tests.Support
{
public class DelegatingSink : ILogEventSink
{
readonly Action<LogEvent> _write;

public DelegatingSink(Action<LogEvent> write)
{
if (write == null) throw new ArgumentNullException(nameof(write));
_write = write;
}

public void Emit(LogEvent logEvent)
{
_write(logEvent);
}

public static LogEvent GetLogEvent(Action<ILogger> writeAction)
{
LogEvent result = null;
var l = new LoggerConfiguration()
.WriteTo.Sink(new DelegatingSink(le => result = le))
.CreateLogger();

writeAction(l);
return result;
}
}
}
12 changes: 12 additions & 0 deletions test/Serilog.Enrichers.Process.Tests/Support/Extensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using Serilog.Events;

namespace Serilog.Tests.Support
{
public static class Extensions
{
public static object LiteralValue(this LogEventPropertyValue @this)
{
return ((ScalarValue)@this).Value;
}
}
}
Empty file removed test/test-project-needed.txt
Empty file.

0 comments on commit 74f35ea

Please sign in to comment.