Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -234,3 +234,4 @@ _Pvt_Extensions

# FAKE - F# Make
.fake/
*.orig
30 changes: 19 additions & 11 deletions Build.ps1
Original file line number Diff line number Diff line change
@@ -1,21 +1,29 @@
echo "build: Build started"

Push-Location $PSScriptRoot

if(Test-Path .\artifacts) { Remove-Item .\artifacts -Force -Recurse }
if(Test-Path .\artifacts) {
echo "build: Cleaning .\artifacts"
Remove-Item .\artifacts -Force -Recurse
}

& dotnet restore
& dotnet restore --no-cache

$revision = @{ $true = $env:APPVEYOR_BUILD_NUMBER; $false = 1 }[$env:APPVEYOR_BUILD_NUMBER -ne $NULL];
$branch = @{ $true = $env:APPVEYOR_REPO_BRANCH; $false = $(git symbolic-ref --short -q HEAD) }[$env:APPVEYOR_REPO_BRANCH -ne $NULL];
$revision = @{ $true = "{0:00000}" -f [convert]::ToInt32("0" + $env:APPVEYOR_BUILD_NUMBER, 10); $false = "local" }[$env:APPVEYOR_BUILD_NUMBER -ne $NULL];
$suffix = @{ $true = ""; $false = "$($branch.Substring(0, [math]::Min(10,$branch.Length)))-$revision"}[$branch -eq "master" -and $revision -ne "local"]

Push-Location src/Serilog.Enrichers.Thread
echo "build: Version suffix is $suffix"

& dotnet pack -c Release -o ..\..\.\artifacts --version-suffix=$revision
if($LASTEXITCODE -ne 0) { exit 1 }
foreach ($src in ls src/*) {
Push-Location $src

Pop-Location
# Push-Location test/Serilog.Enrichers.Thread.Tests
echo "build: Packaging project in $src"

& dotnet pack -c Release -o ..\..\artifacts --version-suffix=$suffix
if($LASTEXITCODE -ne 0) { exit 1 }

# & dotnet test -c Release
# if($LASTEXITCODE -ne 0) { exit 2 }
Pop-Location
}

# Pop-Location
Pop-Location
19 changes: 16 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,28 @@
# Serilog.Enrichers.Thread
# Serilog.Enrichers.Thread [![Build status](https://ci.appveyor.com/api/projects/status/2vgxdy3swg6eaj3f?svg=true)](https://ci.appveyor.com/project/serilog/serilog-enrichers-thread) [![NuGet Version](http://img.shields.io/nuget/v/Serilog.Enrichers.Thread.svg?style=flat)](https://www.nuget.org/packages/Serilog.Enrichers.Thread/)

Enrich Serilog events with properties from the current thread.

[![Build status](https://ci.appveyor.com/api/projects/status/2vgxdy3swg6eaj3f?svg=true)](https://ci.appveyor.com/project/serilog/serilog-enrichers-thread) [![NuGet Version](http://img.shields.io/nuget/v/Serilog.Enrichers.Thread.svg?style=flat)](https://www.nuget.org/packages/Serilog.Enrichers.Thread/)
### Getting started

Install the package from NuGet:

```powershell
Install-Package Serilog.Enrichers.Thread
```

In your logger configuration, apply `Enrich.WithThreadId()`:

```csharp
Log.Logger = new LoggerConfiguration()
.Enrich.WithThreadId()
.CreateLogger();
```

To use the enricher, first install the NuGet package:

```powershell
Install-Package Serilog.Enrichers.Thread
```

* [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).
4 changes: 2 additions & 2 deletions appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ deploy:
secure: nvZ/z+pMS91b3kG4DgfES5AcmwwGoBYQxr9kp4XiJHj25SAlgdIxFx++1N0lFH2x
skip_symbols: true
on:
branch: /^(master)$/
branch: /^(master|dev)$/
- provider: GitHub
auth_token:
secure: ggZTqqV1z0xecDoQbeoy3A7xikShCt9FWZIGp95dG9Fo0p5RAT9oGU0ZekHfUIwk
secure: p4LpVhBKxGS5WqucHxFQ5c7C8cP74kbNB0Z8k9Oxx/PMaDQ1+ibmoexNqVU5ZlmX
artifact: /Serilog.*\.nupkg/
tag: v$(appveyor_build_version)
on:
Expand Down
5 changes: 3 additions & 2 deletions src/Serilog.Enrichers.Thread/Enrichers/ThreadIdEnricher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,12 @@
using System.Threading;
using Serilog.Core;
using Serilog.Events;
using System;

namespace Serilog.Enrichers
{
/// <summary>
/// Enriches log events with a ThreadId property containing the current <see cref="Thread.ManagedThreadId"/>.
/// Enriches log events with a ThreadId property containing the <see cref="Environment.CurrentManagedThreadId"/>.
/// </summary>
public class ThreadIdEnricher : ILogEventEnricher
{
Expand All @@ -35,7 +36,7 @@ public class ThreadIdEnricher : ILogEventEnricher
/// <param name="propertyFactory">Factory for creating new properties to add to the event.</param>
public void Enrich(LogEvent logEvent, ILogEventPropertyFactory propertyFactory)
{
logEvent.AddPropertyIfAbsent(new LogEventProperty(ThreadIdPropertyName, new ScalarValue(Thread.CurrentThread.ManagedThreadId)));
logEvent.AddPropertyIfAbsent(new LogEventProperty(ThreadIdPropertyName, new ScalarValue(Environment.CurrentManagedThreadId)));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@
namespace Serilog
{
/// <summary>
/// Extends <see cref="LoggerConfiguration"/> to add enrichers for <see cref="Thread"/>.
/// Extends <see cref="LoggerConfiguration"/> to add enrichers for <see cref="Environment.CurrentManagedThreadId"/>.
/// capabilities.
/// </summary>
public static class ThreadLoggerConfigurationExtensions
{
/// <summary>
/// Enrich log events with a ThreadId property containing the current <see cref="Thread.ManagedThreadId"/>.
/// Enrich log events with a ThreadId property containing the <see cref="Environment.CurrentManagedThreadId"/>.
/// </summary>
/// <param name="enrichmentConfiguration">Logger enrichment configuration.</param>
/// <returns>Configuration object allowing method chaining.</returns>
Expand Down
5 changes: 2 additions & 3 deletions src/Serilog.Enrichers.Thread/project.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"version": "2.0.0",
"version": "3.0.0-*",
"description": "Enrich Serilog events with properties from the current thread.",
"authors": [ "Serilog Contributors" ],
"packOptions": {
Expand All @@ -19,9 +19,8 @@
"frameworks": {
"net4.5": {
},
"netstandard1.3": {
"netstandard1.0": {
"dependencies": {
"System.Threading.Thread": "4.0.0"
}
}
}
Expand Down