-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #10 from serilog/dev
2.1.1 Release (WIP)
- Loading branch information
Showing
5 changed files
with
49 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,31 @@ | ||
# Serilog.Enrichers.Environment | ||
|
||
The environment enricher for Serilog. | ||
Enriches Serilog events with information from the process environment. | ||
|
||
[![Build status](https://ci.appveyor.com/api/projects/status/yfbvbdxd5vwh6955?svg=true)](https://ci.appveyor.com/project/serilog/serilog-enrichers-environment) [![NuGet Version](http://img.shields.io/nuget/v/Serilog.Enrichers.Environment.svg?style=flat)](https://www.nuget.org/packages/Serilog.Enrichers.Environment/) | ||
|
||
|
||
To use the enricher, first install the NuGet package: | ||
|
||
```powershell | ||
Install-Package Serilog.Enrichers.Environment | ||
``` | ||
|
||
* [Documentation](https://github.com/serilog/serilog/wiki) | ||
Then, apply the enricher to you `LoggerConfiguration`: | ||
|
||
```csharp | ||
Log.Logger = new LoggerConfiguration() | ||
.Enrich.WithMachineName() | ||
// ...other configuration... | ||
.CreateLogger(); | ||
``` | ||
|
||
The `WithMachineName()` enricher will add a `MachineName` property to produced events. | ||
|
||
### Included enrichers | ||
|
||
The package includes: | ||
|
||
* `WithMachineName()` - adds `MachineName` based on either `%COMPUTERNAME%` (Windows) or `$HOSTNAME` (macOS, Linux) | ||
* `WithEnvironmentUserName()` - adds `EnvironmentUserName` based on `USERNAME` and `USERDOMAIN` (if available) | ||
|
||
Copyright © 2016 Serilog Contributors - Provided under the [Apache License, Version 2.0](http://apache.org/licenses/LICENSE-2.0.html). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 24 additions & 0 deletions
24
test/Serilog.Enrichers.Environment.Tests/Enrichers/EnvironmentMachineNameEnricherTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
using Serilog.Events; | ||
using Serilog.Tests.Support; | ||
using Xunit; | ||
|
||
namespace Serilog.Tests.Enrichers | ||
{ | ||
public class EnvironmentMachineNameEnricherTests | ||
{ | ||
[Fact] | ||
public void EnvironmentMachineNameEnricherIsApplied() | ||
{ | ||
LogEvent evt = null; | ||
var log = new LoggerConfiguration() | ||
.Enrich.WithMachineName() | ||
.WriteTo.Sink(new DelegatingSink(e => evt = e)) | ||
.CreateLogger(); | ||
|
||
log.Information(@"Has an MachineName property"); | ||
|
||
Assert.NotNull(evt); | ||
Assert.NotEmpty((string)evt.Properties["MachineName"].LiteralValue()); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters