diff --git a/Serilog.sln b/Serilog.sln index 07fed6825..ccc1f441f 100644 --- a/Serilog.sln +++ b/Serilog.sln @@ -39,6 +39,12 @@ Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Serilog.Sinks.Trace", "src\ EndProject Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Serilog.Settings.AppSettings", "src\Serilog.Settings.AppSettings\Serilog.Settings.AppSettings.xproj", "{0D9F37E3-2CB4-4C0D-A307-32BB71DEFDD4}" EndProject +Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Serilog.Enrichers.Environment", "src\Serilog.Enrichers.Environment\Serilog.Enrichers.Environment.xproj", "{B884782D-6C07-4779-9074-D97F622799A9}" +EndProject +Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Serilog.Enrichers.Process", "src\Serilog.Enrichers.Process\Serilog.Enrichers.Process.xproj", "{2312A998-5E53-4355-9CB6-6014252B3E88}" +EndProject +Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Serilog.Enrichers.Thread", "src\Serilog.Enrichers.Thread\Serilog.Enrichers.Thread.xproj", "{E0BD3797-55A5-4E8C-8DE7-8487BEB75914}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -89,6 +95,18 @@ Global {0D9F37E3-2CB4-4C0D-A307-32BB71DEFDD4}.Debug|Any CPU.Build.0 = Debug|Any CPU {0D9F37E3-2CB4-4C0D-A307-32BB71DEFDD4}.Release|Any CPU.ActiveCfg = Release|Any CPU {0D9F37E3-2CB4-4C0D-A307-32BB71DEFDD4}.Release|Any CPU.Build.0 = Release|Any CPU + {B884782D-6C07-4779-9074-D97F622799A9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {B884782D-6C07-4779-9074-D97F622799A9}.Debug|Any CPU.Build.0 = Debug|Any CPU + {B884782D-6C07-4779-9074-D97F622799A9}.Release|Any CPU.ActiveCfg = Release|Any CPU + {B884782D-6C07-4779-9074-D97F622799A9}.Release|Any CPU.Build.0 = Release|Any CPU + {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 + {E0BD3797-55A5-4E8C-8DE7-8487BEB75914}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {E0BD3797-55A5-4E8C-8DE7-8487BEB75914}.Debug|Any CPU.Build.0 = Debug|Any CPU + {E0BD3797-55A5-4E8C-8DE7-8487BEB75914}.Release|Any CPU.ActiveCfg = Release|Any CPU + {E0BD3797-55A5-4E8C-8DE7-8487BEB75914}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -105,5 +123,8 @@ Global {E85ABEC7-9B4C-432C-9A04-AC5BE9205D9F} = {037440DE-440B-4129-9F7A-09B42D00397E} {8849C92D-2120-4C82-8226-22DF40195237} = {037440DE-440B-4129-9F7A-09B42D00397E} {0D9F37E3-2CB4-4C0D-A307-32BB71DEFDD4} = {037440DE-440B-4129-9F7A-09B42D00397E} + {B884782D-6C07-4779-9074-D97F622799A9} = {037440DE-440B-4129-9F7A-09B42D00397E} + {2312A998-5E53-4355-9CB6-6014252B3E88} = {037440DE-440B-4129-9F7A-09B42D00397E} + {E0BD3797-55A5-4E8C-8DE7-8487BEB75914} = {037440DE-440B-4129-9F7A-09B42D00397E} EndGlobalSection EndGlobal diff --git a/src/Serilog/Enrichers/EnvironmentUserNameEnricher.cs b/src/Serilog.Enrichers.Environment/Enrichers/EnvironmentUserNameEnricher.cs similarity index 97% rename from src/Serilog/Enrichers/EnvironmentUserNameEnricher.cs rename to src/Serilog.Enrichers.Environment/Enrichers/EnvironmentUserNameEnricher.cs index 6e91113ee..08ec13c21 100644 --- a/src/Serilog/Enrichers/EnvironmentUserNameEnricher.cs +++ b/src/Serilog.Enrichers.Environment/Enrichers/EnvironmentUserNameEnricher.cs @@ -1,4 +1,4 @@ -// Copyright 2013-2015 Serilog Contributors +// Copyright 2013-2016 Serilog Contributors // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/src/Serilog/Enrichers/MachineNameEnricher.cs b/src/Serilog.Enrichers.Environment/Enrichers/MachineNameEnricher.cs similarity index 95% rename from src/Serilog/Enrichers/MachineNameEnricher.cs rename to src/Serilog.Enrichers.Environment/Enrichers/MachineNameEnricher.cs index a8691176c..262004407 100644 --- a/src/Serilog/Enrichers/MachineNameEnricher.cs +++ b/src/Serilog.Enrichers.Environment/Enrichers/MachineNameEnricher.cs @@ -1,4 +1,4 @@ -// Copyright 2013-2015 Serilog Contributors +// Copyright 2013-2016 Serilog Contributors // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -11,12 +11,12 @@ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. - -#if !DOTNET5_1 + using System; using Serilog.Core; using Serilog.Events; +using System.Runtime.InteropServices; namespace Serilog.Enrichers { @@ -47,5 +47,4 @@ public void Enrich(LogEvent logEvent, ILogEventPropertyFactory propertyFactory) logEvent.AddPropertyIfAbsent(_cachedProperty); } } -} -#endif +} diff --git a/src/Serilog.Enrichers.Environment/EnvironmentLoggerConfigurationExtensions.cs b/src/Serilog.Enrichers.Environment/EnvironmentLoggerConfigurationExtensions.cs new file mode 100644 index 000000000..51dfb261d --- /dev/null +++ b/src/Serilog.Enrichers.Environment/EnvironmentLoggerConfigurationExtensions.cs @@ -0,0 +1,48 @@ +// Copyright 2013-2016 Serilog Contributors +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +using System; +using Serilog.Configuration; +using Serilog.Enrichers; + +namespace Serilog +{ + public static class EnvironmentLoggerConfigurationExtensions + { + /// + /// Enrich log events with a MachineName property containing the current . + /// + /// Logger enrichment configuration. + /// Configuration object allowing method chaining. + public static LoggerConfiguration WithMachineName( + this LoggerEnrichmentConfiguration enrichmentConfiguration) + { + if (enrichmentConfiguration == null) throw new ArgumentNullException(nameof(enrichmentConfiguration)); + return enrichmentConfiguration.With(); + } + + /// + /// Enriches log events with an EnvironmentUserName property containing [\]. + /// + /// Logger enrichment configuration. + /// Configuration object allowing method chaining. + public static LoggerConfiguration WithEnvironmentUserName( + this LoggerEnrichmentConfiguration enrichmentConfiguration) + { + if (enrichmentConfiguration == null) throw new ArgumentNullException(nameof(enrichmentConfiguration)); + return enrichmentConfiguration.With(); + } + + } +} \ No newline at end of file diff --git a/src/Serilog.Enrichers.Environment/Serilog.Enrichers.Environment.xproj b/src/Serilog.Enrichers.Environment/Serilog.Enrichers.Environment.xproj new file mode 100644 index 000000000..68eace52f --- /dev/null +++ b/src/Serilog.Enrichers.Environment/Serilog.Enrichers.Environment.xproj @@ -0,0 +1,18 @@ + + + + 14.0 + $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion) + + + + b884782d-6c07-4779-9074-d97f622799a9 + Serilog + ..\..\artifacts\obj\$(MSBuildProjectName) + ..\..\artifacts\bin\$(MSBuildProjectName)\ + + + 2.0 + + + \ No newline at end of file diff --git a/src/Serilog.Enrichers.Environment/project.json b/src/Serilog.Enrichers.Environment/project.json new file mode 100644 index 000000000..981dbbd5a --- /dev/null +++ b/src/Serilog.Enrichers.Environment/project.json @@ -0,0 +1,24 @@ +{ + "version": "2.0.0-beta-*", + "description": "The enviornment enrichers for Serilog.", + "authors": [ "Serilog Contributors" ], + "tags": [ "serilog", "machine", "enricher" ], + "projectUrl": "http://serilog.net", + "licenseUrl": "http://www.apache.org/licenses/LICENSE-2.0", + "iconUrl": "http://serilog.net/images/serilog-extension-nuget.png", + "dependencies": { + "Serilog": { "target": "project" } + }, + "compilationOptions": { + "keyFile": "../../assets/Serilog.snk" + }, + "frameworks": { + "net45": { + }, + "dotnet5.4": { + "dependencies": { + "System.Runtime.Extensions": "4.0.11-beta-23516" + } + } + } +} \ No newline at end of file diff --git a/src/Serilog/Enrichers/ProcessIdEnricher.cs b/src/Serilog.Enrichers.Process/Enrichers/ProcessIdEnricher.cs similarity index 98% rename from src/Serilog/Enrichers/ProcessIdEnricher.cs rename to src/Serilog.Enrichers.Process/Enrichers/ProcessIdEnricher.cs index 48596eb22..7e1c1494e 100644 --- a/src/Serilog/Enrichers/ProcessIdEnricher.cs +++ b/src/Serilog.Enrichers.Process/Enrichers/ProcessIdEnricher.cs @@ -11,9 +11,7 @@ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. - -#if PROCESS - + using Serilog.Core; using Serilog.Events; @@ -42,5 +40,4 @@ public void Enrich(LogEvent logEvent, ILogEventPropertyFactory propertyFactory) logEvent.AddPropertyIfAbsent(_cachedProperty); } } -} -#endif +} \ No newline at end of file diff --git a/src/Serilog.Enrichers.Process/ProcessLoggerConfigurationExtensions.cs b/src/Serilog.Enrichers.Process/ProcessLoggerConfigurationExtensions.cs new file mode 100644 index 000000000..6ba98afc4 --- /dev/null +++ b/src/Serilog.Enrichers.Process/ProcessLoggerConfigurationExtensions.cs @@ -0,0 +1,37 @@ +// Copyright 2013-2016 Serilog Contributors +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + + +using System; +using System.Diagnostics; +using Serilog.Configuration; +using Serilog.Enrichers; + +namespace Serilog +{ + public static class ProcessLoggerConfigurationExtensions + { + /// + /// Enrich log events with a ProcessId property containing the current . + /// + /// Logger enrichment configuration. + /// Configuration object allowing method chaining. + public static LoggerConfiguration WithProcessId( + this LoggerEnrichmentConfiguration enrichmentConfiguration) + { + if (enrichmentConfiguration == null) throw new ArgumentNullException(nameof(enrichmentConfiguration)); + return enrichmentConfiguration.With(); + } + } +} \ No newline at end of file diff --git a/src/Serilog.Enrichers.Process/Serilog.Enrichers.Process.xproj b/src/Serilog.Enrichers.Process/Serilog.Enrichers.Process.xproj new file mode 100644 index 000000000..4f211f728 --- /dev/null +++ b/src/Serilog.Enrichers.Process/Serilog.Enrichers.Process.xproj @@ -0,0 +1,18 @@ + + + + 14.0 + $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion) + + + + 2312a998-5e53-4355-9cb6-6014252b3e88 + Serilog + ..\..\artifacts\obj\$(MSBuildProjectName) + ..\..\artifacts\bin\$(MSBuildProjectName)\ + + + 2.0 + + + \ No newline at end of file diff --git a/src/Serilog.Enrichers.Process/project.json b/src/Serilog.Enrichers.Process/project.json new file mode 100644 index 000000000..9e82d91f6 --- /dev/null +++ b/src/Serilog.Enrichers.Process/project.json @@ -0,0 +1,30 @@ +{ + "version": "2.0.0-beta-*", + "description": "The process enricher for Serilog.", + "authors": [ "Serilog Contributors" ], + "tags": [ "serilog", "process", "enricher" ], + "projectUrl": "http://serilog.net", + "licenseUrl": "http://www.apache.org/licenses/LICENSE-2.0", + "iconUrl": "http://serilog.net/images/serilog-extension-nuget.png", + "dependencies": { + "Serilog": { "target": "project" } + }, + "compilationOptions": { + "keyFile": "../../assets/Serilog.snk" + }, + "frameworks": { + "net45": { + }, + "dotnet5.1": { + "dependencies": { + "System.Diagnostics.Process": "4.1.0-beta-23409" + } + }, + "dotnet5.4": { + "dependencies": { + "System.Diagnostics.Process": "4.1.0-beta-23516" + } + } + + } +} \ No newline at end of file diff --git a/src/Serilog/Enrichers/ThreadIdEnricher.cs b/src/Serilog.Enrichers.Thread/Enrichers/ThreadIdEnricher.cs similarity index 100% rename from src/Serilog/Enrichers/ThreadIdEnricher.cs rename to src/Serilog.Enrichers.Thread/Enrichers/ThreadIdEnricher.cs diff --git a/src/Serilog.Enrichers.Thread/Serilog.Enrichers.Thread.xproj b/src/Serilog.Enrichers.Thread/Serilog.Enrichers.Thread.xproj new file mode 100644 index 000000000..0d5aa2c5d --- /dev/null +++ b/src/Serilog.Enrichers.Thread/Serilog.Enrichers.Thread.xproj @@ -0,0 +1,18 @@ + + + + 14.0 + $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion) + + + + e0bd3797-55a5-4e8c-8de7-8487beb75914 + Serilog + ..\..\artifacts\obj\$(MSBuildProjectName) + ..\..\artifacts\bin\$(MSBuildProjectName)\ + + + 2.0 + + + \ No newline at end of file diff --git a/src/Serilog.Enrichers.Thread/ThreadLoggerConfigurationExtensions.cs b/src/Serilog.Enrichers.Thread/ThreadLoggerConfigurationExtensions.cs new file mode 100644 index 000000000..d29abf6a2 --- /dev/null +++ b/src/Serilog.Enrichers.Thread/ThreadLoggerConfigurationExtensions.cs @@ -0,0 +1,39 @@ +// Copyright 2013-2016 Serilog Contributors +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + + +using System; +using System.Threading; +using Serilog.Configuration; +using Serilog.Enrichers; + +namespace Serilog +{ + public static class ThreadLoggerConfigurationExtensions + { + + /// + /// Enrich log events with a ThreadId property containing the current . + /// + /// Logger enrichment configuration. + /// Configuration object allowing method chaining. + /// + public static LoggerConfiguration WithThreadId( + this LoggerEnrichmentConfiguration enrichmentConfiguration) + { + if (enrichmentConfiguration == null) throw new ArgumentNullException(nameof(enrichmentConfiguration)); + return enrichmentConfiguration.With(); + } + } +} \ No newline at end of file diff --git a/src/Serilog.Enrichers.Thread/project.json b/src/Serilog.Enrichers.Thread/project.json new file mode 100644 index 000000000..8d9fdbf55 --- /dev/null +++ b/src/Serilog.Enrichers.Thread/project.json @@ -0,0 +1,21 @@ +{ + "version": "2.0.0-beta-*", + "description": "The thread enricher for Serilog.", + "authors": [ "Serilog Contributors" ], + "tags": [ "serilog", "thread", "enricher" ], + "projectUrl": "http://serilog.net", + "licenseUrl": "http://www.apache.org/licenses/LICENSE-2.0", + "iconUrl": "http://serilog.net/images/serilog-extension-nuget.png", + "dependencies": { + "Serilog": { "target": "project" } + }, + "compilationOptions": { + "keyFile": "../../assets/Serilog.snk" + }, + "frameworks": { + "net45": { + }, + "dotnet5.1": { + } + } +} \ No newline at end of file diff --git a/src/Serilog/LoggerConfigurationExtensions.cs b/src/Serilog/LoggerConfigurationExtensions.cs index 229f71cdd..836e64062 100644 --- a/src/Serilog/LoggerConfigurationExtensions.cs +++ b/src/Serilog/LoggerConfigurationExtensions.cs @@ -34,57 +34,5 @@ namespace Serilog /// public static class LoggerConfigurationExtensions { - /// - /// Enrich log events with a ThreadId property containing the current . - /// - /// Logger enrichment configuration. - /// Configuration object allowing method chaining. - /// - public static LoggerConfiguration WithThreadId( - this LoggerEnrichmentConfiguration enrichmentConfiguration) - { - if (enrichmentConfiguration == null) throw new ArgumentNullException(nameof(enrichmentConfiguration)); - return enrichmentConfiguration.With(); - } - -#if PROCESS - /// - /// Enrich log events with a ProcessId property containing the current . - /// - /// Logger enrichment configuration. - /// Configuration object allowing method chaining. - public static LoggerConfiguration WithProcessId( - this LoggerEnrichmentConfiguration enrichmentConfiguration) - { - if (enrichmentConfiguration == null) throw new ArgumentNullException(nameof(enrichmentConfiguration)); - return enrichmentConfiguration.With(); - } -#endif - -#if !DOTNET5_1 - /// - /// Enrich log events with a MachineName property containing the current . - /// - /// Logger enrichment configuration. - /// Configuration object allowing method chaining. - public static LoggerConfiguration WithMachineName( - this LoggerEnrichmentConfiguration enrichmentConfiguration) - { - if (enrichmentConfiguration == null) throw new ArgumentNullException(nameof(enrichmentConfiguration)); - return enrichmentConfiguration.With(); - } - - /// - /// Enriches log events with an EnvironmentUserName property containing [\]. - /// - /// Logger enrichment configuration. - /// Configuration object allowing method chaining. - public static LoggerConfiguration WithEnvironmentUserName( - this LoggerEnrichmentConfiguration enrichmentConfiguration) - { - if (enrichmentConfiguration == null) throw new ArgumentNullException(nameof(enrichmentConfiguration)); - return enrichmentConfiguration.With(); - } -#endif } } diff --git a/test/Serilog.Tests/Settings/KeyValuePairSettingsTests.cs b/test/Serilog.Tests/Settings/KeyValuePairSettingsTests.cs index c0a976a15..05e484afd 100644 --- a/test/Serilog.Tests/Settings/KeyValuePairSettingsTests.cs +++ b/test/Serilog.Tests/Settings/KeyValuePairSettingsTests.cs @@ -8,6 +8,7 @@ using Serilog.Settings.KeyValuePairs; using Serilog.Sinks.RollingFile; using Serilog.Tests.Support; +using Serilog.Enrichers; namespace Serilog.Tests.AppSettings.Tests { @@ -61,7 +62,21 @@ public void FindsConfigurationAssemblies() public void FindsEventEnrichersWithinAnAssembly() { var eventEnrichers = KeyValuePairSettings - .FindEventEnricherConfigurationMethods(new[] { typeof(Log).GetTypeInfo().Assembly }) + .FindEventEnricherConfigurationMethods(new[] + { + typeof(Log).GetTypeInfo().Assembly + + +#if !DOTNET5_1 + , typeof(MachineNameEnricher).GetTypeInfo().Assembly +#endif + +#if !DOTNET5_1 + , typeof(ProcessIdEnricher).GetTypeInfo().Assembly +#endif + + , typeof(ThreadIdEnricher).GetTypeInfo().Assembly + }) .Select(m => m.Name) .Distinct() .ToList(); diff --git a/test/Serilog.Tests/app.config b/test/Serilog.Tests/app.config index 9a9dafa57..afad5d26f 100644 --- a/test/Serilog.Tests/app.config +++ b/test/Serilog.Tests/app.config @@ -4,6 +4,9 @@ + + + diff --git a/test/Serilog.Tests/project.json b/test/Serilog.Tests/project.json index f9c0178a7..2240c6460 100644 --- a/test/Serilog.Tests/project.json +++ b/test/Serilog.Tests/project.json @@ -17,7 +17,10 @@ "Serilog.Sinks.RollingFile": { "target": "project" }, "Serilog.Sinks.PeriodicBatching": { "target": "project" }, "Serilog.Sinks.Observable": { "target": "project" }, - "Serilog.Sinks.TextWriter": { "target": "project" } + "Serilog.Sinks.TextWriter": { "target": "project" }, + "Serilog.Enrichers.Environment": { "target": "project" }, + "Serilog.Enrichers.Thread": { "target": "project" }, + "Serilog.Enrichers.Process": { "target": "project"} }, "frameworks": { "dnx452": {