Skip to content

Commit

Permalink
Merge pull request #10 from serilog/dev
Browse files Browse the repository at this point in the history
2.1.1 Release (WIP)
  • Loading branch information
nblumhardt authored Nov 22, 2016
2 parents 2aa420a + ee2aca0 commit c4544d0
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 13 deletions.
21 changes: 18 additions & 3 deletions README.md
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).
6 changes: 3 additions & 3 deletions src/Serilog.Enrichers.Environment/project.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"version": "2.1.0-*",
"version": "2.1.1-*",
"description": "Enrich Serilog log events with properties from System.Environment.",
"authors": [
"Serilog Contributors"
Expand All @@ -25,10 +25,10 @@
"net4.5": {
"define": ["ENV_USER_NAME"]
},
"netstandard1.5": {
"netstandard1.3": {
"dependencies": {
"System.Runtime.Extensions": "4.1.0"
}
}
}
}
}
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());
}
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
#if PROCESS

using Serilog.Events;
using Serilog.Events;
using Serilog.Tests.Support;
using Xunit;

Expand All @@ -24,4 +22,3 @@ public void EnvironmentUserNameEnricherIsApplied()
}
}
}
#endif
6 changes: 3 additions & 3 deletions test/Serilog.Enrichers.Environment.Tests/project.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
{
"testRunner": "xunit",
"dependencies": {
"dependencies": {
"xunit": "2.1.0",
"dotnet-test-xunit": "1.0.0-rc2-build10015",
"dotnet-test-xunit": "1.0.0-*",
"Serilog.Enrichers.Environment": {
"target": "project"
}
Expand Down

0 comments on commit c4544d0

Please sign in to comment.