├── .editorconfig ├── .gitattributes ├── assets ├── Serilog.snk ├── serilog-enricher-nuget.png └── Serilog.svg ├── CHANGES.md ├── .idea └── .idea.serilog-enrichers-environment │ └── .idea │ ├── encodings.xml │ ├── vcs.xml │ ├── indexLayout.xml │ └── .gitignore ├── test └── Serilog.Enrichers.Environment.Tests │ ├── Support │ ├── Extensions.cs │ ├── DisposeTrackingSink.cs │ ├── DelegateDisposable.cs │ ├── CollectingSink.cs │ ├── DelegatingEnricher.cs │ ├── DelegatingSink.cs │ ├── Some.cs │ └── DisposableLogger.cs │ ├── Serilog.Enrichers.Environment.Tests.csproj │ └── Enrichers │ ├── EnvironmentMachineNameEnricherTests.cs │ ├── EnvironmentUserNameEnricherTests.cs │ ├── EnvironmentEnvironmenNameEnricherTests.cs │ └── EnvironmenVariableEnricherTests.cs ├── appveyor.yml ├── src └── Serilog.Enrichers.Environment │ ├── Enrichers │ ├── MachineNameEnricher.cs │ ├── EnvironmentUserNameEnricher.cs │ ├── CachedPropertyEnricher.cs │ ├── EnvironmentVariableEnricher.cs │ └── EnvironmentNameEnricher.cs │ ├── Serilog.Enrichers.Environment.csproj │ └── EnvironmentLoggerConfigurationExtensions.cs ├── Build.ps1 ├── README.md ├── serilog-enrichers-environment.sln ├── .gitignore └── LICENSE /.editorconfig: -------------------------------------------------------------------------------- 1 | root=true 2 | 3 | [*] 4 | indent_style = space 5 | indent_size = 4 6 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | 3 | * text=auto 4 | -------------------------------------------------------------------------------- /assets/Serilog.snk: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/serilog/serilog-enrichers-environment/HEAD/assets/Serilog.snk -------------------------------------------------------------------------------- /assets/serilog-enricher-nuget.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/serilog/serilog-enrichers-environment/HEAD/assets/serilog-enricher-nuget.png -------------------------------------------------------------------------------- /CHANGES.md: -------------------------------------------------------------------------------- 1 | 2.1.0 2 | 3 | * #4 - use `$HOSTNAME` to derive machine name on OSX/Linux 4 | 5 | 2.0.0 6 | 7 | * Moved to new project 8 | * DotNet Core support 9 | -------------------------------------------------------------------------------- /.idea/.idea.serilog-enrichers-environment/.idea/encodings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /.idea/.idea.serilog-enrichers-environment/.idea/vcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /.idea/.idea.serilog-enrichers-environment/.idea/indexLayout.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /test/Serilog.Enrichers.Environment.Tests/Support/Extensions.cs: -------------------------------------------------------------------------------- 1 | using Serilog.Events; 2 | 3 | namespace Serilog.Tests.Support 4 | { 5 | public static class Extensions 6 | { 7 | public static object LiteralValue(this LogEventPropertyValue @this) 8 | { 9 | return ((ScalarValue)@this).Value; 10 | } 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /.idea/.idea.serilog-enrichers-environment/.idea/.gitignore: -------------------------------------------------------------------------------- 1 | # Default ignored files 2 | /shelf/ 3 | /workspace.xml 4 | # Rider ignored files 5 | /projectSettingsUpdater.xml 6 | /modules.xml 7 | /.idea.serilog-enrichers-environment.iml 8 | /contentModel.xml 9 | # Editor-based HTTP Client requests 10 | /httpRequests/ 11 | # Datasource local storage ignored files 12 | /dataSources/ 13 | /dataSources.local.xml 14 | -------------------------------------------------------------------------------- /test/Serilog.Enrichers.Environment.Tests/Support/DisposeTrackingSink.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using Serilog.Core; 3 | using Serilog.Events; 4 | 5 | namespace Serilog.Tests.Support 6 | { 7 | class DisposeTrackingSink : ILogEventSink, IDisposable 8 | { 9 | public bool IsDisposed { get; set; } 10 | 11 | public void Emit(LogEvent logEvent) 12 | { 13 | } 14 | 15 | public void Dispose() 16 | { 17 | IsDisposed = true; 18 | } 19 | } 20 | } -------------------------------------------------------------------------------- /test/Serilog.Enrichers.Environment.Tests/Support/DelegateDisposable.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace Serilog.Tests.Support 4 | { 5 | public class DelegateDisposable : IDisposable 6 | { 7 | readonly Action _disposeAction; 8 | bool _disposed; 9 | 10 | public DelegateDisposable(Action disposeAction) 11 | { 12 | _disposeAction = disposeAction; 13 | } 14 | 15 | public void Dispose() 16 | { 17 | if (_disposed) 18 | return; 19 | 20 | _disposeAction(); 21 | _disposed = true; 22 | } 23 | } 24 | } -------------------------------------------------------------------------------- /test/Serilog.Enrichers.Environment.Tests/Support/CollectingSink.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using System.Linq; 3 | using Serilog.Core; 4 | using Serilog.Events; 5 | 6 | namespace Serilog.Tests.Support 7 | { 8 | class CollectingSink : ILogEventSink 9 | { 10 | readonly List _events = new List(); 11 | 12 | public List Events { get { return _events; } } 13 | 14 | public LogEvent SingleEvent { get { return _events.Single(); } } 15 | 16 | public void Emit(LogEvent logEvent) 17 | { 18 | _events.Add(logEvent); 19 | } 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /test/Serilog.Enrichers.Environment.Tests/Serilog.Enrichers.Environment.Tests.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | net48;net8.0 5 | false 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /test/Serilog.Enrichers.Environment.Tests/Support/DelegatingEnricher.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using Serilog.Core; 3 | using Serilog.Events; 4 | 5 | namespace Serilog.Tests.Support 6 | { 7 | class DelegatingEnricher : ILogEventEnricher 8 | { 9 | readonly Action _enrich; 10 | 11 | public DelegatingEnricher(Action enrich) 12 | { 13 | if (enrich == null) throw new ArgumentNullException(nameof(enrich)); 14 | _enrich = enrich; 15 | } 16 | 17 | public void Enrich(LogEvent logEvent, ILogEventPropertyFactory propertyFactory) 18 | { 19 | _enrich(logEvent, propertyFactory); 20 | } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /appveyor.yml: -------------------------------------------------------------------------------- 1 | version: '{build}' 2 | skip_tags: true 3 | image: Visual Studio 2022 4 | build_script: 5 | - pwsh: ./Build.ps1 6 | test: off 7 | artifacts: 8 | - path: artifacts/Serilog.*.nupkg 9 | - path: artifacts/Serilog.*.snupkg 10 | deploy: 11 | - provider: NuGet 12 | api_key: 13 | secure: Fh92tRIFbe1FAiyD8lTThWgAorQ1vV+eFYMlUK0iLHBBenJcy/UYc1qj6kgHvUcO 14 | skip_symbols: true 15 | on: 16 | branch: /^(main|dev)$/ 17 | - provider: GitHub 18 | auth_token: 19 | secure: p4LpVhBKxGS5WqucHxFQ5c7C8cP74kbNB0Z8k9Oxx/PMaDQ1+ibmoexNqVU5ZlmX 20 | artifacts: 21 | /Serilog.*\.nupkg/ 22 | /Serilog.*\.snupkg/ 23 | tag: v$(appveyor_build_version) 24 | on: 25 | branch: main 26 | -------------------------------------------------------------------------------- /test/Serilog.Enrichers.Environment.Tests/Enrichers/EnvironmentMachineNameEnricherTests.cs: -------------------------------------------------------------------------------- 1 | using Serilog.Events; 2 | using Serilog.Tests.Support; 3 | using Xunit; 4 | 5 | namespace Serilog.Tests.Enrichers 6 | { 7 | public class EnvironmentMachineNameEnricherTests 8 | { 9 | [Fact] 10 | public void EnvironmentMachineNameEnricherIsApplied() 11 | { 12 | LogEvent evt = null; 13 | var log = new LoggerConfiguration() 14 | .Enrich.WithMachineName() 15 | .WriteTo.Sink(new DelegatingSink(e => evt = e)) 16 | .CreateLogger(); 17 | 18 | log.Information(@"Has an MachineName property"); 19 | 20 | Assert.NotNull(evt); 21 | Assert.NotEmpty((string)evt.Properties["MachineName"].LiteralValue()); 22 | } 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /test/Serilog.Enrichers.Environment.Tests/Enrichers/EnvironmentUserNameEnricherTests.cs: -------------------------------------------------------------------------------- 1 | using Serilog.Events; 2 | using Serilog.Tests.Support; 3 | using Xunit; 4 | 5 | namespace Serilog.Tests.Enrichers 6 | { 7 | public class EnvironmentUserNameEnricherTests 8 | { 9 | [Fact] 10 | public void EnvironmentUserNameEnricherIsApplied() 11 | { 12 | LogEvent evt = null; 13 | var log = new LoggerConfiguration() 14 | .Enrich.WithEnvironmentUserName() 15 | .WriteTo.Sink(new DelegatingSink(e => evt = e)) 16 | .CreateLogger(); 17 | 18 | log.Information(@"Has an EnvironmentUserName property with [domain\]userName"); 19 | 20 | Assert.NotNull(evt); 21 | Assert.NotEmpty((string)evt.Properties["EnvironmentUserName"].LiteralValue()); 22 | } 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /test/Serilog.Enrichers.Environment.Tests/Enrichers/EnvironmentEnvironmenNameEnricherTests.cs: -------------------------------------------------------------------------------- 1 | using Serilog.Events; 2 | using Serilog.Tests.Support; 3 | using Xunit; 4 | 5 | namespace Serilog.Tests.Enrichers 6 | { 7 | public class EnvironmentEnvironmenNameEnricherTests 8 | { 9 | [Fact] 10 | public void EnvironmentNameEnricherIsApplied() 11 | { 12 | LogEvent evt = null; 13 | var log = new LoggerConfiguration() 14 | .Enrich.WithEnvironmentName() 15 | .WriteTo.Sink(new DelegatingSink(e => evt = e)) 16 | .CreateLogger(); 17 | 18 | log.Information(@"Has an EnvironmenName property with the value of the DOTNET_ENVIRONMENT or ASPNETCORE_ENVIRONMENT environment variable."); 19 | 20 | Assert.NotNull(evt); 21 | Assert.NotEmpty((string)evt.Properties["EnvironmentName"].LiteralValue()); 22 | } 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /test/Serilog.Enrichers.Environment.Tests/Support/DelegatingSink.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using Serilog.Core; 3 | using Serilog.Events; 4 | 5 | namespace Serilog.Tests.Support 6 | { 7 | public class DelegatingSink : ILogEventSink 8 | { 9 | readonly Action _write; 10 | 11 | public DelegatingSink(Action write) 12 | { 13 | if (write == null) throw new ArgumentNullException(nameof(write)); 14 | _write = write; 15 | } 16 | 17 | public void Emit(LogEvent logEvent) 18 | { 19 | _write(logEvent); 20 | } 21 | 22 | public static LogEvent GetLogEvent(Action writeAction) 23 | { 24 | LogEvent result = null; 25 | var l = new LoggerConfiguration() 26 | .WriteTo.Sink(new DelegatingSink(le => result = le)) 27 | .CreateLogger(); 28 | 29 | writeAction(l); 30 | return result; 31 | } 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/Serilog.Enrichers.Environment/Enrichers/MachineNameEnricher.cs: -------------------------------------------------------------------------------- 1 | // Copyright 2013-2022 Serilog Contributors 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | using System; 16 | using Serilog.Core; 17 | using Serilog.Events; 18 | 19 | namespace Serilog.Enrichers; 20 | 21 | /// 22 | /// Enriches log events with a MachineName property containing . 23 | /// 24 | sealed class MachineNameEnricher : CachedPropertyEnricher 25 | { 26 | /// 27 | /// The property name added to enriched log events. 28 | /// 29 | const string MachineNamePropertyName = "MachineName"; 30 | 31 | protected override LogEventProperty CreateProperty(ILogEventPropertyFactory propertyFactory) 32 | { 33 | var machineName = Environment.MachineName; 34 | return propertyFactory.CreateProperty(MachineNamePropertyName, machineName); 35 | } 36 | } -------------------------------------------------------------------------------- /Build.ps1: -------------------------------------------------------------------------------- 1 | echo "build: Build started" 2 | 3 | Push-Location $PSScriptRoot 4 | 5 | if(Test-Path .\artifacts) { 6 | echo "build: Cleaning .\artifacts" 7 | Remove-Item .\artifacts -Force -Recurse 8 | } 9 | 10 | & dotnet restore --no-cache 11 | 12 | $branch = @{ $true = $env:APPVEYOR_REPO_BRANCH; $false = $(git symbolic-ref --short -q HEAD) }[$env:APPVEYOR_REPO_BRANCH -ne $NULL]; 13 | $revision = @{ $true = "{0:00000}" -f [convert]::ToInt32("0" + $env:APPVEYOR_BUILD_NUMBER, 10); $false = "local" }[$env:APPVEYOR_BUILD_NUMBER -ne $NULL]; 14 | $suffix = @{ $true = ""; $false = "$($branch.Substring(0, [math]::Min(10,$branch.Length)))-$revision"}[$branch -eq "main" -and $revision -ne "local"] 15 | $commitHash = $(git rev-parse --short HEAD) 16 | $buildSuffix = @{ $true = "$($suffix)-$($commitHash)"; $false = "$($branch)-$($commitHash)" }[$suffix -ne ""] 17 | 18 | echo "build: Package version suffix is $suffix" 19 | echo "build: Build version suffix is $buildSuffix" 20 | 21 | foreach ($src in ls src/*) { 22 | Push-Location $src 23 | 24 | echo "build: Packaging project in $src" 25 | 26 | & dotnet build -c Release --version-suffix=$buildSuffix -p:ContinuousIntegrationBuild=true 27 | if ($suffix) { 28 | & dotnet pack -c Release -o ..\..\artifacts --version-suffix=$suffix --no-build 29 | } else { 30 | & dotnet pack -c Release -o ..\..\artifacts --no-build 31 | } 32 | if($LASTEXITCODE -ne 0) { throw "build failed" } 33 | 34 | Pop-Location 35 | } 36 | 37 | foreach ($test in ls test/*.Tests) { 38 | Push-Location $test 39 | 40 | echo "build: Testing project in $test" 41 | 42 | & dotnet test -c Release 43 | if($LASTEXITCODE -ne 0) { throw "tests failed" } 44 | 45 | Pop-Location 46 | } 47 | 48 | Pop-Location -------------------------------------------------------------------------------- /src/Serilog.Enrichers.Environment/Enrichers/EnvironmentUserNameEnricher.cs: -------------------------------------------------------------------------------- 1 | // Copyright 2013-2022 Serilog Contributors 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | using System; 16 | using Serilog.Core; 17 | using Serilog.Events; 18 | 19 | namespace Serilog.Enrichers; 20 | 21 | /// 22 | /// Enriches log events with an EnvironmentUserName property containing [\]. 23 | /// 24 | sealed class EnvironmentUserNameEnricher : CachedPropertyEnricher 25 | { 26 | /// 27 | /// The property name added to enriched log events. 28 | /// 29 | const string EnvironmentUserNamePropertyName = "EnvironmentUserName"; 30 | 31 | protected override LogEventProperty CreateProperty(ILogEventPropertyFactory propertyFactory) 32 | { 33 | var userDomainName = Environment.UserDomainName; 34 | var userName = Environment.UserName; 35 | var environmentUserName = !string.IsNullOrWhiteSpace(userDomainName) ? $@"{userDomainName}\{userName}" : userName; 36 | 37 | return propertyFactory.CreateProperty(EnvironmentUserNamePropertyName, environmentUserName); 38 | } 39 | } -------------------------------------------------------------------------------- /src/Serilog.Enrichers.Environment/Enrichers/CachedPropertyEnricher.cs: -------------------------------------------------------------------------------- 1 | // Copyright 2013-2022 Serilog Contributors 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | using Serilog.Core; 16 | using Serilog.Events; 17 | 18 | namespace Serilog.Enrichers; 19 | 20 | abstract class CachedPropertyEnricher: ILogEventEnricher 21 | { 22 | LogEventProperty? CachedProperty { get; set; } 23 | 24 | /// 25 | /// Enrich the log event. 26 | /// 27 | /// The log event to enrich. 28 | /// Factory for creating new properties to add to the event. 29 | public void Enrich(LogEvent logEvent, ILogEventPropertyFactory propertyFactory) 30 | { 31 | logEvent.AddPropertyIfAbsent(GetLogEventProperty(propertyFactory)); 32 | } 33 | 34 | LogEventProperty GetLogEventProperty(ILogEventPropertyFactory propertyFactory) 35 | { 36 | // Don't care about thread-safety, in the worst case the field gets overwritten and one 37 | // property will be GCed 38 | return CachedProperty ??= CreateProperty(propertyFactory); 39 | } 40 | 41 | protected abstract LogEventProperty CreateProperty(ILogEventPropertyFactory propertyFactory); 42 | } 43 | -------------------------------------------------------------------------------- /src/Serilog.Enrichers.Environment/Enrichers/EnvironmentVariableEnricher.cs: -------------------------------------------------------------------------------- 1 | // Copyright 2013-2022 Serilog Contributors 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | using System; 16 | using Serilog.Core; 17 | using Serilog.Events; 18 | 19 | namespace Serilog.Enrichers; 20 | 21 | /// 22 | /// Enriches log events with a EnvironmentName property containing the value of the ASPNETCORE_ENVIRONMENT or DOTNET_ENVIRONMENT environment variable. 23 | /// 24 | sealed class EnvironmentVariableEnricher : CachedPropertyEnricher 25 | { 26 | readonly string _envVarName; 27 | 28 | /// 29 | /// The property name added to enriched log events. 30 | /// 31 | string EnvironmentVariablePropertyName { get; } 32 | 33 | public EnvironmentVariableEnricher(string envVarName, string? propertyName) 34 | { 35 | _envVarName = envVarName; 36 | EnvironmentVariablePropertyName = propertyName ?? envVarName; 37 | } 38 | 39 | protected override LogEventProperty CreateProperty(ILogEventPropertyFactory propertyFactory) 40 | { 41 | var environmentVariableValue = Environment.GetEnvironmentVariable(_envVarName); 42 | 43 | return propertyFactory.CreateProperty(EnvironmentVariablePropertyName, environmentVariableValue); 44 | } 45 | } -------------------------------------------------------------------------------- /src/Serilog.Enrichers.Environment/Enrichers/EnvironmentNameEnricher.cs: -------------------------------------------------------------------------------- 1 | // Copyright 2013-2022 Serilog Contributors 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | using System; 16 | using Serilog.Core; 17 | using Serilog.Events; 18 | 19 | namespace Serilog.Enrichers; 20 | 21 | /// 22 | /// Enriches log events with a EnvironmentName property containing the value of the ASPNETCORE_ENVIRONMENT or DOTNET_ENVIRONMENT environment variable. 23 | /// 24 | sealed class EnvironmentNameEnricher : CachedPropertyEnricher 25 | { 26 | /// 27 | /// The property name added to enriched log events. 28 | /// 29 | const string EnvironmentNamePropertyName = "EnvironmentName"; 30 | 31 | protected override LogEventProperty CreateProperty(ILogEventPropertyFactory propertyFactory) 32 | { 33 | var environmentName = Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT"); 34 | 35 | if (string.IsNullOrWhiteSpace(environmentName)) 36 | { 37 | environmentName = Environment.GetEnvironmentVariable("DOTNET_ENVIRONMENT"); 38 | } 39 | 40 | if (string.IsNullOrWhiteSpace(environmentName)) 41 | { 42 | environmentName = "Production"; 43 | } 44 | 45 | return propertyFactory.CreateProperty(EnvironmentNamePropertyName, environmentName); 46 | } 47 | } -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Serilog.Enrichers.Environment 2 | 3 | Enriches Serilog events with information from the execution environment. 4 | 5 | [![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/) 6 | 7 | To use the enricher, first install the NuGet package: 8 | 9 | ```powershell 10 | dotnet add package Serilog.Enrichers.Environment 11 | ``` 12 | 13 | Then, apply the enricher to you `LoggerConfiguration`: 14 | 15 | ```csharp 16 | Log.Logger = new LoggerConfiguration() 17 | .Enrich.WithMachineName() 18 | // ...other configuration... 19 | .CreateLogger(); 20 | ``` 21 | 22 | The `WithMachineName()` enricher will add a `MachineName` property to produced events. 23 | 24 | ### Included enrichers 25 | 26 | The package includes: 27 | 28 | * `WithMachineName()` - adds `MachineName` based on either `%COMPUTERNAME%` (Windows) or `$HOSTNAME` (macOS, Linux) 29 | * `WithEnvironmentUserName()` - adds `EnvironmentUserName` based on `USERNAME` and `USERDOMAIN` (if available) 30 | * `WithEnvironmentName()` - adds `EnvironmentName` based on `ASPNETCORE_ENVIRONMENT` or `DOTNET_ENVIRONMENT` (when both are available then 'ASPNETCORE_ENVIRONMENT' takes precedence, when none are available then the fallback value will be 'Production') 31 | * `WithEnvironmentVariable(string environmentVariableName, string propertyName = null)` - adds an `environmentVariableName` property to the log event with the value for the specified environment variable. Optional `propertyName` will override `environmentVariableName` as the name of the attached property. 32 | 33 | Copyright © 2016 Serilog Contributors - Provided under the [Apache License, Version 2.0](http://apache.org/licenses/LICENSE-2.0.html). 34 | -------------------------------------------------------------------------------- /test/Serilog.Enrichers.Environment.Tests/Enrichers/EnvironmenVariableEnricherTests.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using Serilog.Events; 3 | using Serilog.Tests.Support; 4 | using Xunit; 5 | 6 | namespace Serilog.Tests.Enrichers 7 | { 8 | public class EnvironmentVariableEnricherTests 9 | { 10 | 11 | [Fact] 12 | public void EnvironmentVariable_EnvVariableMissing_EnricherAcceptsNullValue() 13 | { 14 | Environment.SetEnvironmentVariable("CUSTOM_VARIABLE", null); 15 | LogEvent evt = null; 16 | var log = new LoggerConfiguration() 17 | .Enrich.WithEnvironmentVariable("CUSTOM_VARIABLE") 18 | .WriteTo.Sink(new DelegatingSink(e => evt = e)) 19 | .CreateLogger(); 20 | 21 | log.Information("EnvironmentVariable CUSTOM_VARIABLE missing."); 22 | 23 | Assert.NotNull(evt); 24 | Assert.Null((string)evt.Properties["CUSTOM_VARIABLE"].LiteralValue()); 25 | } 26 | 27 | [Fact] 28 | public void EnvironmentVariable_PropertyValue_EnricherUsesSpecificPropertyValue() 29 | { 30 | Environment.SetEnvironmentVariable("CUSTOM_VARIABLE", null); 31 | LogEvent evt = null; 32 | var log = new LoggerConfiguration() 33 | .Enrich.WithEnvironmentVariable("CUSTOM_VARIABLE", "PropertyName") 34 | .WriteTo.Sink(new DelegatingSink(e => evt = e)) 35 | .CreateLogger(); 36 | 37 | log.Information("PropertyName has been overriden"); 38 | 39 | Assert.NotNull(evt); 40 | Assert.Null((string)evt.Properties["PropertyName"].LiteralValue()); 41 | } 42 | 43 | [Fact] 44 | public void EnvironmentVariable_EnvVariableMissing_EnricherUsesSetValue() 45 | { 46 | Environment.SetEnvironmentVariable("CUSTOM_VARIABLE", "random-value"); 47 | LogEvent evt = null; 48 | var log = new LoggerConfiguration() 49 | .Enrich.WithEnvironmentVariable("CUSTOM_VARIABLE") 50 | .WriteTo.Sink(new DelegatingSink(e => evt = e)) 51 | .CreateLogger(); 52 | 53 | log.Information("EnvironmentVariable CUSTOM_VARIABLE has a value"); 54 | 55 | Assert.NotNull(evt); 56 | Assert.Equal("random-value", (string)evt.Properties["CUSTOM_VARIABLE"].LiteralValue()); 57 | } 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /src/Serilog.Enrichers.Environment/Serilog.Enrichers.Environment.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Enrich Serilog log events with properties from System.Environment. 5 | 3.0.2 6 | 3.0.0.0 7 | true 8 | ../../assets/Serilog.snk 9 | true 10 | Serilog Contributors 11 | 12 | net471;net462 13 | 16 | $(TargetFrameworks);net8.0;net6.0;netstandard2.0 17 | serilog;machine;enricher 18 | serilog-enricher-nuget.png 19 | https://github.com/serilog/serilog-enrichers-environment 20 | Apache-2.0 21 | https://github.com/serilog/serilog-enrichers-environment 22 | git 23 | true 24 | Serilog 25 | README.md 26 | 12 27 | enable 28 | true 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | -------------------------------------------------------------------------------- /serilog-enrichers-environment.sln: -------------------------------------------------------------------------------- 1 | 2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 15 4 | VisualStudioVersion = 15.0.26430.14 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{037440DE-440B-4129-9F7A-09B42D00397E}" 7 | EndProject 8 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "assets", "assets", "{E9D1B5E1-DEB9-4A04-8BAB-24EC7240ADAF}" 9 | ProjectSection(SolutionItems) = preProject 10 | Build.ps1 = Build.ps1 11 | README.md = README.md 12 | assets\Serilog.snk = assets\Serilog.snk 13 | appveyor.yml = appveyor.yml 14 | EndProjectSection 15 | EndProject 16 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "test", "test", "{406006F7-12FA-4A8A-ADC8-80E5338F5275}" 17 | EndProject 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}" 21 | EndProject 22 | Global 23 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 24 | Debug|Any CPU = Debug|Any CPU 25 | Release|Any CPU = Release|Any CPU 26 | EndGlobalSection 27 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 28 | {B884782D-6C07-4779-9074-D97F622799A9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 29 | {B884782D-6C07-4779-9074-D97F622799A9}.Debug|Any CPU.Build.0 = Debug|Any CPU 30 | {B884782D-6C07-4779-9074-D97F622799A9}.Release|Any CPU.ActiveCfg = Release|Any CPU 31 | {B884782D-6C07-4779-9074-D97F622799A9}.Release|Any CPU.Build.0 = Release|Any CPU 32 | {3C2D8E01-5580-426A-BDD9-EC59CD98E618}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 33 | {3C2D8E01-5580-426A-BDD9-EC59CD98E618}.Debug|Any CPU.Build.0 = Debug|Any CPU 34 | {3C2D8E01-5580-426A-BDD9-EC59CD98E618}.Release|Any CPU.ActiveCfg = Release|Any CPU 35 | {3C2D8E01-5580-426A-BDD9-EC59CD98E618}.Release|Any CPU.Build.0 = Release|Any CPU 36 | EndGlobalSection 37 | GlobalSection(SolutionProperties) = preSolution 38 | HideSolutionNode = FALSE 39 | EndGlobalSection 40 | GlobalSection(NestedProjects) = preSolution 41 | {B884782D-6C07-4779-9074-D97F622799A9} = {037440DE-440B-4129-9F7A-09B42D00397E} 42 | {3C2D8E01-5580-426A-BDD9-EC59CD98E618} = {406006F7-12FA-4A8A-ADC8-80E5338F5275} 43 | EndGlobalSection 44 | EndGlobal 45 | -------------------------------------------------------------------------------- /test/Serilog.Enrichers.Environment.Tests/Support/Some.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.IO; 3 | using System.Linq; 4 | using System.Threading; 5 | using Serilog.Events; 6 | using Serilog.Parsing; 7 | 8 | namespace Serilog.Tests.Support 9 | { 10 | static class Some 11 | { 12 | static int Counter; 13 | 14 | public static int Int() 15 | { 16 | return Interlocked.Increment(ref Counter); 17 | } 18 | 19 | public static decimal Decimal() 20 | { 21 | return Int() + 0.123m; 22 | } 23 | 24 | public static string String(string tag = null) 25 | { 26 | return (tag ?? "") + "__" + Int(); 27 | } 28 | 29 | public static TimeSpan TimeSpan() 30 | { 31 | return System.TimeSpan.FromMinutes(Int()); 32 | } 33 | 34 | public static DateTime Instant() 35 | { 36 | return new DateTime(2012, 10, 28) + TimeSpan(); 37 | } 38 | 39 | public static DateTimeOffset OffsetInstant() 40 | { 41 | return new DateTimeOffset(Instant()); 42 | } 43 | 44 | public static LogEvent LogEvent(DateTimeOffset? timestamp = null, LogEventLevel level = LogEventLevel.Information) 45 | { 46 | return new LogEvent(timestamp ?? OffsetInstant(), level, 47 | null, MessageTemplate(), Enumerable.Empty()); 48 | } 49 | 50 | public static LogEvent InformationEvent(DateTimeOffset? timestamp = null) 51 | { 52 | return LogEvent(timestamp, LogEventLevel.Information); 53 | } 54 | 55 | public static LogEvent DebugEvent(DateTimeOffset? timestamp = null) 56 | { 57 | return LogEvent(timestamp, LogEventLevel.Debug); 58 | } 59 | 60 | public static LogEventProperty LogEventProperty() 61 | { 62 | return new LogEventProperty(String(), new ScalarValue(Int())); 63 | } 64 | 65 | public static string NonexistentTempFilePath() 66 | { 67 | return Path.Combine(Path.GetTempPath(), Guid.NewGuid() + ".txt"); 68 | } 69 | 70 | public static string TempFilePath() 71 | { 72 | return Path.GetTempFileName(); 73 | } 74 | 75 | public static string TempFolderPath() 76 | { 77 | var dir = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString()); 78 | Directory.CreateDirectory(dir); 79 | return dir; 80 | } 81 | 82 | public static MessageTemplate MessageTemplate() 83 | { 84 | return new MessageTemplateParser().Parse(String()); 85 | } 86 | } 87 | } 88 | -------------------------------------------------------------------------------- /src/Serilog.Enrichers.Environment/EnvironmentLoggerConfigurationExtensions.cs: -------------------------------------------------------------------------------- 1 | // Copyright 2013-2016 Serilog Contributors 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | using System; 16 | using Serilog.Configuration; 17 | using Serilog.Enrichers; 18 | 19 | namespace Serilog; 20 | 21 | /// 22 | /// Extends to add enrichers for . 23 | /// capabilities. 24 | /// 25 | public static class EnvironmentLoggerConfigurationExtensions 26 | { 27 | /// 28 | /// Enrich log events with a EnvironmentName property containing the value of the ASPNETCORE_ENVIRONMENT 29 | /// or DOTNET_ENVIRONMENT environment variable. 30 | /// 31 | /// Logger enrichment configuration. 32 | /// Configuration object allowing method chaining. 33 | public static LoggerConfiguration WithEnvironmentName( 34 | this LoggerEnrichmentConfiguration enrichmentConfiguration) 35 | { 36 | if (enrichmentConfiguration == null) throw new ArgumentNullException(nameof(enrichmentConfiguration)); 37 | return enrichmentConfiguration.With(); 38 | } 39 | 40 | /// 41 | /// Enrich log events with a MachineName property containing the current . 42 | /// 43 | /// Logger enrichment configuration. 44 | /// Configuration object allowing method chaining. 45 | public static LoggerConfiguration WithMachineName( 46 | this LoggerEnrichmentConfiguration enrichmentConfiguration) 47 | { 48 | if (enrichmentConfiguration == null) throw new ArgumentNullException(nameof(enrichmentConfiguration)); 49 | return enrichmentConfiguration.With(); 50 | } 51 | 52 | /// 53 | /// Enriches log events with an EnvironmentUserName property containing . 54 | /// 55 | /// Logger enrichment configuration. 56 | /// Configuration object allowing method chaining. 57 | public static LoggerConfiguration WithEnvironmentUserName( 58 | this LoggerEnrichmentConfiguration enrichmentConfiguration) 59 | { 60 | if (enrichmentConfiguration == null) throw new ArgumentNullException(nameof(enrichmentConfiguration)); 61 | return enrichmentConfiguration.With(); 62 | } 63 | 64 | /// 65 | /// Enriches log events with an property containing the value of the specified Environment Variable using 66 | /// . 67 | /// 68 | /// Logger enrichment configuration. 69 | /// The name of the Environment Variable 70 | /// The Optional name of the property. If empty is used 71 | /// Configuration object allowing method chaining. 72 | public static LoggerConfiguration WithEnvironmentVariable( 73 | this LoggerEnrichmentConfiguration enrichmentConfiguration, string environmentVariableName, string? propertyName = null) 74 | { 75 | if (enrichmentConfiguration == null) throw new ArgumentNullException(nameof(enrichmentConfiguration)); 76 | var environmentVariableEnricher = new EnvironmentVariableEnricher(environmentVariableName, propertyName); 77 | return enrichmentConfiguration.With(environmentVariableEnricher); 78 | } 79 | } -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | ## Ignore Visual Studio temporary files, build results, and 2 | ## files generated by popular Visual Studio add-ons. 3 | 4 | # User-specific files 5 | *.suo 6 | *.user 7 | *.userosscache 8 | *.sln.docstates 9 | 10 | # User-specific files (MonoDevelop/Xamarin Studio) 11 | *.userprefs 12 | 13 | # Build results 14 | [Dd]ebug/ 15 | [Dd]ebugPublic/ 16 | [Rr]elease/ 17 | [Rr]eleases/ 18 | x64/ 19 | x86/ 20 | bld/ 21 | [Bb]in/ 22 | [Oo]bj/ 23 | 24 | # Visual Studio 2015 cache/options directory 25 | .vs/ 26 | # Uncomment if you have tasks that create the project's static files in wwwroot 27 | #wwwroot/ 28 | 29 | # MSTest test Results 30 | [Tt]est[Rr]esult*/ 31 | [Bb]uild[Ll]og.* 32 | 33 | # NUNIT 34 | *.VisualState.xml 35 | TestResult.xml 36 | 37 | # Build Results of an ATL Project 38 | [Dd]ebugPS/ 39 | [Rr]eleasePS/ 40 | dlldata.c 41 | 42 | # DNX 43 | project.lock.json 44 | artifacts/ 45 | 46 | *_i.c 47 | *_p.c 48 | *_i.h 49 | *.ilk 50 | *.meta 51 | *.obj 52 | *.pch 53 | *.pdb 54 | *.pgc 55 | *.pgd 56 | *.rsp 57 | *.sbr 58 | *.tlb 59 | *.tli 60 | *.tlh 61 | *.tmp 62 | *.tmp_proj 63 | *.log 64 | *.vspscc 65 | *.vssscc 66 | .builds 67 | *.pidb 68 | *.svclog 69 | *.scc 70 | 71 | # Chutzpah Test files 72 | _Chutzpah* 73 | 74 | # Visual C++ cache files 75 | ipch/ 76 | *.aps 77 | *.ncb 78 | *.opendb 79 | *.opensdf 80 | *.sdf 81 | *.cachefile 82 | 83 | # Visual Studio profiler 84 | *.psess 85 | *.vsp 86 | *.vspx 87 | *.sap 88 | 89 | # TFS 2012 Local Workspace 90 | $tf/ 91 | 92 | # Guidance Automation Toolkit 93 | *.gpState 94 | 95 | # ReSharper is a .NET coding add-in 96 | _ReSharper*/ 97 | *.[Rr]e[Ss]harper 98 | *.DotSettings.user 99 | 100 | # JustCode is a .NET coding add-in 101 | .JustCode 102 | 103 | # TeamCity is a build add-in 104 | _TeamCity* 105 | 106 | # DotCover is a Code Coverage Tool 107 | *.dotCover 108 | 109 | # NCrunch 110 | _NCrunch_* 111 | .*crunch*.local.xml 112 | nCrunchTemp_* 113 | 114 | # MightyMoose 115 | *.mm.* 116 | AutoTest.Net/ 117 | 118 | # Web workbench (sass) 119 | .sass-cache/ 120 | 121 | # Installshield output folder 122 | [Ee]xpress/ 123 | 124 | # DocProject is a documentation generator add-in 125 | DocProject/buildhelp/ 126 | DocProject/Help/*.HxT 127 | DocProject/Help/*.HxC 128 | DocProject/Help/*.hhc 129 | DocProject/Help/*.hhk 130 | DocProject/Help/*.hhp 131 | DocProject/Help/Html2 132 | DocProject/Help/html 133 | 134 | # Click-Once directory 135 | publish/ 136 | 137 | # Publish Web Output 138 | *.[Pp]ublish.xml 139 | *.azurePubxml 140 | # TODO: Comment the next line if you want to checkin your web deploy settings 141 | # but database connection strings (with potential passwords) will be unencrypted 142 | *.pubxml 143 | *.publishproj 144 | 145 | # NuGet Packages 146 | *.nupkg 147 | # The packages folder can be ignored because of Package Restore 148 | **/packages/* 149 | # except build/, which is used as an MSBuild target. 150 | !**/packages/build/ 151 | # Uncomment if necessary however generally it will be regenerated when needed 152 | #!**/packages/repositories.config 153 | # NuGet v3's project.json files produces more ignoreable files 154 | *.nuget.props 155 | *.nuget.targets 156 | 157 | # Microsoft Azure Build Output 158 | csx/ 159 | *.build.csdef 160 | 161 | # Microsoft Azure Emulator 162 | ecf/ 163 | rcf/ 164 | 165 | # Microsoft Azure ApplicationInsights config file 166 | ApplicationInsights.config 167 | 168 | # Windows Store app package directory 169 | AppPackages/ 170 | BundleArtifacts/ 171 | 172 | # Visual Studio cache files 173 | # files ending in .cache can be ignored 174 | *.[Cc]ache 175 | # but keep track of directories ending in .cache 176 | !*.[Cc]ache/ 177 | 178 | # Others 179 | ClientBin/ 180 | ~$* 181 | *~ 182 | *.dbmdl 183 | *.dbproj.schemaview 184 | *.pfx 185 | *.publishsettings 186 | node_modules/ 187 | orleans.codegen.cs 188 | 189 | # RIA/Silverlight projects 190 | Generated_Code/ 191 | 192 | # Backup & report files from converting an old project file 193 | # to a newer Visual Studio version. Backup files are not needed, 194 | # because we have git ;-) 195 | _UpgradeReport_Files/ 196 | Backup*/ 197 | UpgradeLog*.XML 198 | UpgradeLog*.htm 199 | 200 | # SQL Server files 201 | *.mdf 202 | *.ldf 203 | 204 | # Business Intelligence projects 205 | *.rdl.data 206 | *.bim.layout 207 | *.bim_*.settings 208 | 209 | # Microsoft Fakes 210 | FakesAssemblies/ 211 | 212 | # GhostDoc plugin setting file 213 | *.GhostDoc.xml 214 | 215 | # Node.js Tools for Visual Studio 216 | .ntvs_analysis.dat 217 | 218 | # Visual Studio 6 build log 219 | *.plg 220 | 221 | # Visual Studio 6 workspace options file 222 | *.opt 223 | 224 | # Visual Studio LightSwitch build output 225 | **/*.HTMLClient/GeneratedArtifacts 226 | **/*.DesktopClient/GeneratedArtifacts 227 | **/*.DesktopClient/ModelManifest.xml 228 | **/*.Server/GeneratedArtifacts 229 | **/*.Server/ModelManifest.xml 230 | _Pvt_Extensions 231 | 232 | # Paket dependency manager 233 | .paket/paket.exe 234 | 235 | # FAKE - F# Make 236 | .fake/ 237 | -------------------------------------------------------------------------------- /assets/Serilog.svg: -------------------------------------------------------------------------------- 1 | 2 | image/svg+xml 44 | 55 | 56 | 57 | 70 | 75 | 79 | 83 | 87 | 91 | 95 | 99 | 103 | 110 | 117 | 123 | 128 | 131 | 134 | 137 | 140 | 143 | 146 | 149 | 156 | 163 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "{}" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright {yyyy} {name of copyright owner} 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /test/Serilog.Enrichers.Environment.Tests/Support/DisposableLogger.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using Serilog.Core; 4 | using Serilog.Events; 5 | 6 | namespace Serilog.Tests.Support 7 | { 8 | public class DisposableLogger : ILogger, IDisposable 9 | { 10 | public bool Disposed { get; set; } 11 | 12 | public void Dispose() 13 | { 14 | Disposed = true; 15 | } 16 | 17 | public ILogger ForContext(ILogEventEnricher enricher) 18 | { 19 | throw new NotImplementedException(); 20 | } 21 | 22 | public ILogger ForContext(IEnumerable enrichers) 23 | { 24 | throw new NotImplementedException(); 25 | } 26 | 27 | public ILogger ForContext(string propertyName, object value, bool destructureObjects = false) 28 | { 29 | throw new NotImplementedException(); 30 | } 31 | 32 | public ILogger ForContext() 33 | { 34 | throw new NotImplementedException(); 35 | } 36 | 37 | public ILogger ForContext(Type source) 38 | { 39 | throw new NotImplementedException(); 40 | } 41 | 42 | public void Write(LogEvent logEvent) 43 | { 44 | throw new NotImplementedException(); 45 | } 46 | 47 | public void Write(LogEventLevel level, string messageTemplate) 48 | { 49 | throw new NotImplementedException(); 50 | } 51 | 52 | public void Write(LogEventLevel level, string messageTemplate, T propertyValue) 53 | { 54 | throw new NotImplementedException(); 55 | } 56 | 57 | public void Write(LogEventLevel level, string messageTemplate, T0 propertyValue0, T1 propertyValue1) 58 | { 59 | throw new NotImplementedException(); 60 | } 61 | 62 | public void Write(LogEventLevel level, string messageTemplate, T0 propertyValue0, T1 propertyValue1, 63 | T2 propertyValue2) 64 | { 65 | throw new NotImplementedException(); 66 | } 67 | 68 | public void Write(LogEventLevel level, string messageTemplate, params object[] propertyValues) 69 | { 70 | throw new NotImplementedException(); 71 | } 72 | 73 | public void Write(LogEventLevel level, Exception exception, string messageTemplate) 74 | { 75 | throw new NotImplementedException(); 76 | } 77 | 78 | public void Write(LogEventLevel level, Exception exception, string messageTemplate, T propertyValue) 79 | { 80 | throw new NotImplementedException(); 81 | } 82 | 83 | public void Write(LogEventLevel level, Exception exception, string messageTemplate, T0 propertyValue0, 84 | T1 propertyValue1) 85 | { 86 | throw new NotImplementedException(); 87 | } 88 | 89 | public void Write(LogEventLevel level, Exception exception, string messageTemplate, T0 propertyValue0, 90 | T1 propertyValue1, T2 propertyValue2) 91 | { 92 | throw new NotImplementedException(); 93 | } 94 | 95 | public void Write(LogEventLevel level, Exception exception, string messageTemplate, params object[] propertyValues) 96 | { 97 | throw new NotImplementedException(); 98 | } 99 | 100 | public bool IsEnabled(LogEventLevel level) 101 | { 102 | throw new NotImplementedException(); 103 | } 104 | 105 | public void Verbose(string messageTemplate) 106 | { 107 | throw new NotImplementedException(); 108 | } 109 | 110 | public void Verbose(string messageTemplate, T propertyValue) 111 | { 112 | throw new NotImplementedException(); 113 | } 114 | 115 | public void Verbose(string messageTemplate, T0 propertyValue0, T1 propertyValue1) 116 | { 117 | throw new NotImplementedException(); 118 | } 119 | 120 | public void Verbose(string messageTemplate, T0 propertyValue0, T1 propertyValue1, T2 propertyValue2) 121 | { 122 | throw new NotImplementedException(); 123 | } 124 | 125 | public void Verbose(string messageTemplate, params object[] propertyValues) 126 | { 127 | throw new NotImplementedException(); 128 | } 129 | 130 | public void Verbose(Exception exception, string messageTemplate) 131 | { 132 | throw new NotImplementedException(); 133 | } 134 | 135 | public void Verbose(Exception exception, string messageTemplate, T propertyValue) 136 | { 137 | throw new NotImplementedException(); 138 | } 139 | 140 | public void Verbose(Exception exception, string messageTemplate, T0 propertyValue0, T1 propertyValue1) 141 | { 142 | throw new NotImplementedException(); 143 | } 144 | 145 | public void Verbose(Exception exception, string messageTemplate, T0 propertyValue0, T1 propertyValue1, 146 | T2 propertyValue2) 147 | { 148 | throw new NotImplementedException(); 149 | } 150 | 151 | public void Verbose(Exception exception, string messageTemplate, params object[] propertyValues) 152 | { 153 | throw new NotImplementedException(); 154 | } 155 | 156 | public void Debug(string messageTemplate) 157 | { 158 | throw new NotImplementedException(); 159 | } 160 | 161 | public void Debug(string messageTemplate, T propertyValue) 162 | { 163 | throw new NotImplementedException(); 164 | } 165 | 166 | public void Debug(string messageTemplate, T0 propertyValue0, T1 propertyValue1) 167 | { 168 | throw new NotImplementedException(); 169 | } 170 | 171 | public void Debug(string messageTemplate, T0 propertyValue0, T1 propertyValue1, T2 propertyValue2) 172 | { 173 | throw new NotImplementedException(); 174 | } 175 | 176 | public void Debug(string messageTemplate, params object[] propertyValues) 177 | { 178 | throw new NotImplementedException(); 179 | } 180 | 181 | public void Debug(Exception exception, string messageTemplate) 182 | { 183 | throw new NotImplementedException(); 184 | } 185 | 186 | public void Debug(Exception exception, string messageTemplate, T propertyValue) 187 | { 188 | throw new NotImplementedException(); 189 | } 190 | 191 | public void Debug(Exception exception, string messageTemplate, T0 propertyValue0, T1 propertyValue1) 192 | { 193 | throw new NotImplementedException(); 194 | } 195 | 196 | public void Debug(Exception exception, string messageTemplate, T0 propertyValue0, T1 propertyValue1, 197 | T2 propertyValue2) 198 | { 199 | throw new NotImplementedException(); 200 | } 201 | 202 | public void Debug(Exception exception, string messageTemplate, params object[] propertyValues) 203 | { 204 | throw new NotImplementedException(); 205 | } 206 | 207 | public void Information(string messageTemplate) 208 | { 209 | throw new NotImplementedException(); 210 | } 211 | 212 | public void Information(string messageTemplate, T propertyValue) 213 | { 214 | throw new NotImplementedException(); 215 | } 216 | 217 | public void Information(string messageTemplate, T0 propertyValue0, T1 propertyValue1) 218 | { 219 | throw new NotImplementedException(); 220 | } 221 | 222 | public void Information(string messageTemplate, T0 propertyValue0, T1 propertyValue1, T2 propertyValue2) 223 | { 224 | throw new NotImplementedException(); 225 | } 226 | 227 | public void Information(string messageTemplate, params object[] propertyValues) 228 | { 229 | throw new NotImplementedException(); 230 | } 231 | 232 | public void Information(Exception exception, string messageTemplate) 233 | { 234 | throw new NotImplementedException(); 235 | } 236 | 237 | public void Information(Exception exception, string messageTemplate, T propertyValue) 238 | { 239 | throw new NotImplementedException(); 240 | } 241 | 242 | public void Information(Exception exception, string messageTemplate, T0 propertyValue0, T1 propertyValue1) 243 | { 244 | throw new NotImplementedException(); 245 | } 246 | 247 | public void Information(Exception exception, string messageTemplate, T0 propertyValue0, T1 propertyValue1, 248 | T2 propertyValue2) 249 | { 250 | throw new NotImplementedException(); 251 | } 252 | 253 | public void Information(Exception exception, string messageTemplate, params object[] propertyValues) 254 | { 255 | throw new NotImplementedException(); 256 | } 257 | 258 | public void Warning(string messageTemplate) 259 | { 260 | throw new NotImplementedException(); 261 | } 262 | 263 | public void Warning(string messageTemplate, T propertyValue) 264 | { 265 | throw new NotImplementedException(); 266 | } 267 | 268 | public void Warning(string messageTemplate, T0 propertyValue0, T1 propertyValue1) 269 | { 270 | throw new NotImplementedException(); 271 | } 272 | 273 | public void Warning(string messageTemplate, T0 propertyValue0, T1 propertyValue1, T2 propertyValue2) 274 | { 275 | throw new NotImplementedException(); 276 | } 277 | 278 | public void Warning(string messageTemplate, params object[] propertyValues) 279 | { 280 | throw new NotImplementedException(); 281 | } 282 | 283 | public void Warning(Exception exception, string messageTemplate) 284 | { 285 | throw new NotImplementedException(); 286 | } 287 | 288 | public void Warning(Exception exception, string messageTemplate, T propertyValue) 289 | { 290 | throw new NotImplementedException(); 291 | } 292 | 293 | public void Warning(Exception exception, string messageTemplate, T0 propertyValue0, T1 propertyValue1) 294 | { 295 | throw new NotImplementedException(); 296 | } 297 | 298 | public void Warning(Exception exception, string messageTemplate, T0 propertyValue0, T1 propertyValue1, 299 | T2 propertyValue2) 300 | { 301 | throw new NotImplementedException(); 302 | } 303 | 304 | public void Warning(Exception exception, string messageTemplate, params object[] propertyValues) 305 | { 306 | throw new NotImplementedException(); 307 | } 308 | 309 | public void Error(string messageTemplate) 310 | { 311 | throw new NotImplementedException(); 312 | } 313 | 314 | public void Error(string messageTemplate, T propertyValue) 315 | { 316 | throw new NotImplementedException(); 317 | } 318 | 319 | public void Error(string messageTemplate, T0 propertyValue0, T1 propertyValue1) 320 | { 321 | throw new NotImplementedException(); 322 | } 323 | 324 | public void Error(string messageTemplate, T0 propertyValue0, T1 propertyValue1, T2 propertyValue2) 325 | { 326 | throw new NotImplementedException(); 327 | } 328 | 329 | public void Error(string messageTemplate, params object[] propertyValues) 330 | { 331 | throw new NotImplementedException(); 332 | } 333 | 334 | public void Error(Exception exception, string messageTemplate) 335 | { 336 | throw new NotImplementedException(); 337 | } 338 | 339 | public void Error(Exception exception, string messageTemplate, T propertyValue) 340 | { 341 | throw new NotImplementedException(); 342 | } 343 | 344 | public void Error(Exception exception, string messageTemplate, T0 propertyValue0, T1 propertyValue1) 345 | { 346 | throw new NotImplementedException(); 347 | } 348 | 349 | public void Error(Exception exception, string messageTemplate, T0 propertyValue0, T1 propertyValue1, 350 | T2 propertyValue2) 351 | { 352 | throw new NotImplementedException(); 353 | } 354 | 355 | public void Error(Exception exception, string messageTemplate, params object[] propertyValues) 356 | { 357 | throw new NotImplementedException(); 358 | } 359 | 360 | public void Fatal(string messageTemplate) 361 | { 362 | throw new NotImplementedException(); 363 | } 364 | 365 | public void Fatal(string messageTemplate, T propertyValue) 366 | { 367 | throw new NotImplementedException(); 368 | } 369 | 370 | public void Fatal(string messageTemplate, T0 propertyValue0, T1 propertyValue1) 371 | { 372 | throw new NotImplementedException(); 373 | } 374 | 375 | public void Fatal(string messageTemplate, T0 propertyValue0, T1 propertyValue1, T2 propertyValue2) 376 | { 377 | throw new NotImplementedException(); 378 | } 379 | 380 | public void Fatal(string messageTemplate, params object[] propertyValues) 381 | { 382 | throw new NotImplementedException(); 383 | } 384 | 385 | public void Fatal(Exception exception, string messageTemplate) 386 | { 387 | throw new NotImplementedException(); 388 | } 389 | 390 | public void Fatal(Exception exception, string messageTemplate, T propertyValue) 391 | { 392 | throw new NotImplementedException(); 393 | } 394 | 395 | public void Fatal(Exception exception, string messageTemplate, T0 propertyValue0, T1 propertyValue1) 396 | { 397 | throw new NotImplementedException(); 398 | } 399 | 400 | public void Fatal(Exception exception, string messageTemplate, T0 propertyValue0, T1 propertyValue1, 401 | T2 propertyValue2) 402 | { 403 | throw new NotImplementedException(); 404 | } 405 | 406 | public void Fatal(Exception exception, string messageTemplate, params object[] propertyValues) 407 | { 408 | throw new NotImplementedException(); 409 | } 410 | 411 | public bool BindMessageTemplate(string messageTemplate, object[] propertyValues, out MessageTemplate parsedTemplate, 412 | out IEnumerable boundProperties) 413 | { 414 | throw new NotImplementedException(); 415 | } 416 | 417 | public bool BindProperty(string propertyName, object value, bool destructureObjects, out LogEventProperty property) 418 | { 419 | throw new NotImplementedException(); 420 | } 421 | } 422 | } --------------------------------------------------------------------------------