From 8edfa166d2c6af7b4576f183ae046aaabad468af Mon Sep 17 00:00:00 2001 From: Colin Young Date: Tue, 19 Jan 2016 16:32:38 -0500 Subject: [PATCH 01/12] Enable LogContext for .Net Core. https://github.com/serilog/serilog/issues/588 --- src/Serilog/Context/ImmutableStack.cs | 12 ++++ src/Serilog/Context/LogContext.cs | 56 ++++++++++++++++--- .../Enrichers/EnvironmentUserNameEnricher.cs | 12 ++-- src/Serilog/project.json | 19 ++----- test/Serilog.Tests/Context/LogContextTests.cs | 14 ++++- test/Serilog.Tests/project.json | 6 +- 6 files changed, 88 insertions(+), 31 deletions(-) diff --git a/src/Serilog/Context/ImmutableStack.cs b/src/Serilog/Context/ImmutableStack.cs index 90f779041..d05d90634 100644 --- a/src/Serilog/Context/ImmutableStack.cs +++ b/src/Serilog/Context/ImmutableStack.cs @@ -21,15 +21,25 @@ namespace Serilog.Context { // Needed because of the shallow-copying behaviour of // LogicalCallContext. +#if REMOTING [Serializable] class ImmutableStack : IEnumerable, ISerializable +#else + class ImmutableStack : IEnumerable +#endif { readonly ImmutableStack _under; readonly T _top; +#if REMOTING public ImmutableStack(SerializationInfo info, StreamingContext context) { } +#else + public ImmutableStack(StreamingContext context) + { + } +#endif ImmutableStack() { @@ -68,9 +78,11 @@ System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator() public T Top => _top; +#if REMOTING void ISerializable.GetObjectData(SerializationInfo info, StreamingContext context) { } +#endif } } #endif \ No newline at end of file diff --git a/src/Serilog/Context/LogContext.cs b/src/Serilog/Context/LogContext.cs index 07bfc3c56..b23b83d9a 100644 --- a/src/Serilog/Context/LogContext.cs +++ b/src/Serilog/Context/LogContext.cs @@ -12,9 +12,16 @@ // See the License for the specific language governing permissions and // limitations under the License. + #if LOGCONTEXT using System; +#if REMOTING using System.Runtime.Remoting.Messaging; +#endif +#if ASYNCLOCAL +using System.Collections.Generic; +using System.Threading; +#endif using Serilog.Core; using Serilog.Core.Enrichers; using Serilog.Events; @@ -42,11 +49,19 @@ namespace Serilog.Context /// /// /// The scope of the context is the current logical thread, using - /// (and so is - /// preserved across async/await calls). +#if ASYNCLOCAL + /// +#else + /// +#endif + /// (and so is preserved across async/await calls). public static class LogContext { +#if ASYNCLOCAL + static readonly AsyncLocal> data = new AsyncLocal>(); +#else static readonly string DataSlotName = typeof(LogContext).FullName; +#endif /// /// When calling into appdomains without Serilog loaded, e.g. via remoting or during unit testing, @@ -136,10 +151,13 @@ static ImmutableStack Enrichers { get { - +#if ASYNCLOCAL + return data.Value; +#else var data = CallContext.LogicalGetData(DataSlotName); ImmutableStack context; +#if REMOTING if (PermitCrossAppDomainCalls) { context = ((Wrapper) data)?.Value; @@ -148,18 +166,39 @@ static ImmutableStack Enrichers { context = (ImmutableStack)data; } - +#else + context = data; +#endif return context; +#endif } set { - - var context = !PermitCrossAppDomainCalls ? (object)value : new Wrapper { Value = value }; - +#if ASYNCLOCAL + data.Value = GetContext(value); +#else + var context = GetContext(value); CallContext.LogicalSetData(DataSlotName, context); +#endif } } +#if REMOTING + static object GetContext(ImmutableStack value) + { + var context = !PermitCrossAppDomainCalls ? (object) value : new Wrapper + { + Value = value + }; + return context; + } +#else + static ImmutableStack GetContext(ImmutableStack value) + { + return value; + } +#endif + internal static void Enrich(LogEvent logEvent, ILogEventPropertyFactory propertyFactory) { var enrichers = Enrichers; @@ -187,10 +226,13 @@ public void Dispose() } } +#if REMOTING sealed class Wrapper : MarshalByRefObject { public ImmutableStack Value { get; set; } } +#endif } } + #endif diff --git a/src/Serilog/Enrichers/EnvironmentUserNameEnricher.cs b/src/Serilog/Enrichers/EnvironmentUserNameEnricher.cs index 6e91113ee..e81d6e255 100644 --- a/src/Serilog/Enrichers/EnvironmentUserNameEnricher.cs +++ b/src/Serilog/Enrichers/EnvironmentUserNameEnricher.cs @@ -21,7 +21,11 @@ namespace Serilog.Enrichers { /// +#if USERNAMEFROMENV + /// Enriches log events with an EnvironmentUserName property containing [Environment.GetEnvironmentVariable("USERDOMAIN")\]Environment.GetEnvironmentVariable("USERNAME"). +#else /// Enriches log events with an EnvironmentUserName property containing [\]. +#endif /// public class EnvironmentUserNameEnricher : ILogEventEnricher { @@ -45,12 +49,12 @@ public void Enrich(LogEvent logEvent, ILogEventPropertyFactory propertyFactory) private static string GetEnvironmentUserName() { -#if !DOTNET5_4 - var userDomainName = Environment.UserDomainName; - var userName = Environment.UserName; -#else +#if USERNAMEFROMENV var userDomainName = Environment.GetEnvironmentVariable("USERNAME"); var userName = Environment.GetEnvironmentVariable("USERDOMAIN"); +#else + var userDomainName = Environment.UserDomainName; + var userName = Environment.UserName; #endif return !string.IsNullOrWhiteSpace(userDomainName) ? $@"{userDomainName}\{userName}" : userName; } diff --git a/src/Serilog/project.json b/src/Serilog/project.json index 1b08f9f00..51a9aff00 100644 --- a/src/Serilog/project.json +++ b/src/Serilog/project.json @@ -7,22 +7,10 @@ "licenseUrl": "http://www.apache.org/licenses/LICENSE-2.0", "iconUrl": "http://serilog.net/images/serilog-nuget.png", "frameworks": { - "net40": { - "compilationOptions": { - "keyFile": "../../assets/Serilog.snk", - "define": [ "APPSETTINGS", "LOGCONTEXT", "PROCESS", "FILE_IO", "PERIODIC_BATCHING" ] - }, - "frameworkAssemblies": { - "System.Configuration": "" - }, - "dependencies": { - "Microsoft.Bcl.Async": "1.0.168" - } - }, "net45": { "compilationOptions": { "keyFile": "../../assets/Serilog.snk", - "define": [ "APPSETTINGS", "LOGCONTEXT", "PROCESS", "FILE_IO", "PERIODIC_BATCHING" ] + "define": [ "APPSETTINGS", "LOGCONTEXT", "PROCESS", "FILE_IO", "PERIODIC_BATCHING", "REMOTING" ] }, "frameworkAssemblies": { "System.Configuration": "" @@ -42,6 +30,7 @@ "System.Linq": "4.0.1-beta-23516", "System.Reflection.Extensions": "4.0.1-beta-23516", "System.Runtime.Extensions": "4.0.11-beta-23516", + "System.Runtime.Serialization.Primitives": "4.1.0-beta-23516", "System.Text.RegularExpressions": "4.0.11-beta-23516", "System.Threading": "4.0.11-beta-23516", "System.Threading.Thread": "4.0.0-beta-23516" @@ -50,7 +39,8 @@ "dotnet5.4": { "compilationOptions": { "keyFile": "../../assets/Serilog.snk", - "define": [ "PROCESS", "FILE_IO", "PERIODIC_BATCHING", "NO_TIMER", "NO_APPDOMAIN" ] + "define": [ "ASYNCLOCAL", "LOGCONTEXT", "PROCESS", "FILE_IO", "PERIODIC_BATCHING", "NO_TIMER", "NO_APPDOMAIN", "USERNAMEFROMENV" ] + }, "dependencies": { "Microsoft.CSharp": "4.0.1-beta-23516", @@ -64,6 +54,7 @@ "System.Linq": "4.0.1-beta-23516", "System.Reflection.Extensions": "4.0.1-beta-23516", "System.Runtime.Extensions": "4.0.11-beta-23516", + "System.Runtime.Serialization.Primitives": "4.1.0-beta-23516", "System.Text.RegularExpressions": "4.0.11-beta-23516", "System.Threading": "4.0.11-beta-23516", "System.Threading.Thread": "4.0.0-beta-23516" diff --git a/test/Serilog.Tests/Context/LogContextTests.cs b/test/Serilog.Tests/Context/LogContextTests.cs index bfe9e6ff3..48ca526eb 100644 --- a/test/Serilog.Tests/Context/LogContextTests.cs +++ b/test/Serilog.Tests/Context/LogContextTests.cs @@ -1,12 +1,14 @@ -#if LOGCONTEXT -using System; +using System; using System.IO; -using System.Runtime.Remoting.Messaging; +#if LOGCONTEXT using Xunit; using Serilog.Context; using Serilog.Events; using Serilog.Core.Enrichers; using Serilog.Tests.Support; +#if REMOTING +using System.Runtime.Remoting.Messaging; +#endif using System.Threading; using System.Threading.Tasks; @@ -17,7 +19,9 @@ public class LogContextTests public LogContextTests() { LogContext.PermitCrossAppDomainCalls = false; +#if !ASYNCLOCAL CallContext.LogicalSetData(typeof(LogContext).FullName, null); +#endif } [Fact] @@ -138,6 +142,7 @@ public async Task ContextPropertiesPersistWhenCrossAppDomainCallsAreEnabled() } } +#if !NO_APPDOMAIN // Must not actually try to pass context across domains, // since user property types may not be serializable. // Fails if the Serilog assemblies cannot be loaded in the @@ -180,6 +185,7 @@ public void DoesNotPreventCrossDomainCalls() AppDomain.Unload(domain); } } +#endif [Fact] public void WhenSuspendedAllPropertiesAreRemovedFromTheContext() @@ -205,6 +211,7 @@ public void WhenSuspendedAllPropertiesAreRemovedFromTheContext() } } +#if REMOTING public class RemotelyCallable : MarshalByRefObject { public bool IsCallable() @@ -223,5 +230,6 @@ public bool IsCallable() return s == "42"; } } +#endif } #endif diff --git a/test/Serilog.Tests/project.json b/test/Serilog.Tests/project.json index 206132437..c5a5fbfe9 100644 --- a/test/Serilog.Tests/project.json +++ b/test/Serilog.Tests/project.json @@ -20,10 +20,10 @@ "Serilog.Sinks.TextWriter": {"target": "project"} }, "frameworks": { - "dnx451": { + "dnx452": { "compilationOptions": { "keyFile": "../../assets/Serilog.snk", - "define": [ "APPSETTINGS", "LOGCONTEXT", "PROCESS", "FILE_IO", "PERIODIC_BATCHING", "INTERNAL_TESTS" ] + "define": [ "APPSETTINGS", "LOGCONTEXT", "PROCESS", "FILE_IO", "PERIODIC_BATCHING", "INTERNAL_TESTS", "REMOTING" ] }, "frameworkAssemblies": { "System.Configuration": "" @@ -31,7 +31,7 @@ }, "dnxcore50": { "compilationOptions": { - "define": [ "FILE_IO", "PERIODIC_BATCHING" ] + "define": [ "ASYNCLOCAL", "LOGCONTEXT", "FILE_IO", "PERIODIC_BATCHING", "NO_APPDOMAIN" ] }, "dependencies": { "Microsoft.CSharp": "4.0.1-beta-23516", From 92c0ffae2f4b460a1abf888d7724f7f686770d6a Mon Sep 17 00:00:00 2001 From: Colin Young Date: Wed, 27 Jan 2016 12:02:45 -0500 Subject: [PATCH 02/12] Slight reduction in #ifdefs. --- src/Serilog/Context/LogContext.cs | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/src/Serilog/Context/LogContext.cs b/src/Serilog/Context/LogContext.cs index b23b83d9a..a64da8e6e 100644 --- a/src/Serilog/Context/LogContext.cs +++ b/src/Serilog/Context/LogContext.cs @@ -147,20 +147,30 @@ static ImmutableStack GetOrCreateEnricherStack() return enrichers; } - static ImmutableStack Enrichers +#if ASYNCLOCAL + static ImmutableStack Enrichers { get { -#if ASYNCLOCAL return data.Value; + } + set + { + data.Value = GetContext(value); + } + } #else + static ImmutableStack Enrichers + { + get + { var data = CallContext.LogicalGetData(DataSlotName); ImmutableStack context; #if REMOTING if (PermitCrossAppDomainCalls) { - context = ((Wrapper) data)?.Value; + context = ((Wrapper)data)?.Value; } else { @@ -170,18 +180,14 @@ static ImmutableStack Enrichers context = data; #endif return context; -#endif } set { -#if ASYNCLOCAL - data.Value = GetContext(value); -#else var context = GetContext(value); CallContext.LogicalSetData(DataSlotName, context); -#endif } } +#endif #if REMOTING static object GetContext(ImmutableStack value) From e5a4d1b2be9b7fd4af2682409987951b1b80424d Mon Sep 17 00:00:00 2001 From: Colin Young Date: Wed, 27 Jan 2016 16:53:35 -0500 Subject: [PATCH 03/12] Removing unused constructor. --- src/Serilog/Context/ImmutableStack.cs | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/Serilog/Context/ImmutableStack.cs b/src/Serilog/Context/ImmutableStack.cs index d05d90634..2f77aab6f 100644 --- a/src/Serilog/Context/ImmutableStack.cs +++ b/src/Serilog/Context/ImmutableStack.cs @@ -15,7 +15,9 @@ #if LOGCONTEXT using System; using System.Collections.Generic; +#if REMOTING using System.Runtime.Serialization; +#endif namespace Serilog.Context { @@ -35,10 +37,6 @@ class ImmutableStack : IEnumerable public ImmutableStack(SerializationInfo info, StreamingContext context) { } -#else - public ImmutableStack(StreamingContext context) - { - } #endif ImmutableStack() From 65173508411809e5d57e10b2e37d03b610057667 Mon Sep 17 00:00:00 2001 From: Colin Young Date: Wed, 27 Jan 2016 17:01:27 -0500 Subject: [PATCH 04/12] Adding extra context to lead to correct location in MSDN. --- src/Serilog/Context/LogContext.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Serilog/Context/LogContext.cs b/src/Serilog/Context/LogContext.cs index a64da8e6e..798457bd5 100644 --- a/src/Serilog/Context/LogContext.cs +++ b/src/Serilog/Context/LogContext.cs @@ -52,7 +52,7 @@ namespace Serilog.Context #if ASYNCLOCAL /// #else - /// + /// #endif /// (and so is preserved across async/await calls). public static class LogContext From ab37bfd2898c330e7c36d624a18746600c1a8170 Mon Sep 17 00:00:00 2001 From: Colin Young Date: Wed, 27 Jan 2016 17:03:38 -0500 Subject: [PATCH 05/12] Consolidating #ifdef blocks to make code easier to read/maintain. --- src/Serilog/Context/ImmutableStack.cs | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/Serilog/Context/ImmutableStack.cs b/src/Serilog/Context/ImmutableStack.cs index 2f77aab6f..ed67ab198 100644 --- a/src/Serilog/Context/ImmutableStack.cs +++ b/src/Serilog/Context/ImmutableStack.cs @@ -37,6 +37,10 @@ class ImmutableStack : IEnumerable public ImmutableStack(SerializationInfo info, StreamingContext context) { } + + void ISerializable.GetObjectData(SerializationInfo info, StreamingContext context) + { + } #endif ImmutableStack() @@ -76,11 +80,6 @@ System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator() public T Top => _top; -#if REMOTING - void ISerializable.GetObjectData(SerializationInfo info, StreamingContext context) - { - } -#endif } } #endif \ No newline at end of file From 42dfa307ff62685d5929c0287f1cf35c06ae82fa Mon Sep 17 00:00:00 2001 From: Colin Young Date: Wed, 27 Jan 2016 17:08:47 -0500 Subject: [PATCH 06/12] Fix naming for consistency. --- src/Serilog/Context/LogContext.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Serilog/Context/LogContext.cs b/src/Serilog/Context/LogContext.cs index 798457bd5..34652e3a2 100644 --- a/src/Serilog/Context/LogContext.cs +++ b/src/Serilog/Context/LogContext.cs @@ -58,7 +58,7 @@ namespace Serilog.Context public static class LogContext { #if ASYNCLOCAL - static readonly AsyncLocal> data = new AsyncLocal>(); + static readonly AsyncLocal> Data = new AsyncLocal>(); #else static readonly string DataSlotName = typeof(LogContext).FullName; #endif @@ -152,11 +152,11 @@ static ImmutableStack Enrichers { get { - return data.Value; + return Data.Value; } set { - data.Value = GetContext(value); + Data.Value = GetContext(value); } } #else From 4e9c2a38e7a2c95a0cfba4605e86305c0f96e3cf Mon Sep 17 00:00:00 2001 From: Colin Young Date: Thu, 28 Jan 2016 08:40:12 -0500 Subject: [PATCH 07/12] Removing unrelated changes from enrichers. --- src/Serilog/Enrichers/EnvironmentUserNameEnricher.cs | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/src/Serilog/Enrichers/EnvironmentUserNameEnricher.cs b/src/Serilog/Enrichers/EnvironmentUserNameEnricher.cs index e81d6e255..6e91113ee 100644 --- a/src/Serilog/Enrichers/EnvironmentUserNameEnricher.cs +++ b/src/Serilog/Enrichers/EnvironmentUserNameEnricher.cs @@ -21,11 +21,7 @@ namespace Serilog.Enrichers { /// -#if USERNAMEFROMENV - /// Enriches log events with an EnvironmentUserName property containing [Environment.GetEnvironmentVariable("USERDOMAIN")\]Environment.GetEnvironmentVariable("USERNAME"). -#else /// Enriches log events with an EnvironmentUserName property containing [\]. -#endif /// public class EnvironmentUserNameEnricher : ILogEventEnricher { @@ -49,12 +45,12 @@ public void Enrich(LogEvent logEvent, ILogEventPropertyFactory propertyFactory) private static string GetEnvironmentUserName() { -#if USERNAMEFROMENV - var userDomainName = Environment.GetEnvironmentVariable("USERNAME"); - var userName = Environment.GetEnvironmentVariable("USERDOMAIN"); -#else +#if !DOTNET5_4 var userDomainName = Environment.UserDomainName; var userName = Environment.UserName; +#else + var userDomainName = Environment.GetEnvironmentVariable("USERNAME"); + var userName = Environment.GetEnvironmentVariable("USERDOMAIN"); #endif return !string.IsNullOrWhiteSpace(userDomainName) ? $@"{userDomainName}\{userName}" : userName; } From 09afb7839d9bd51ccc51b467dc37c4757350949b Mon Sep 17 00:00:00 2001 From: Colin Young Date: Thu, 28 Jan 2016 19:36:14 -0500 Subject: [PATCH 08/12] Moving PermitCrossAppDomainCalls inside REMOTING #ifdef. --- src/Serilog/Context/LogContext.cs | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/Serilog/Context/LogContext.cs b/src/Serilog/Context/LogContext.cs index 34652e3a2..958886b13 100644 --- a/src/Serilog/Context/LogContext.cs +++ b/src/Serilog/Context/LogContext.cs @@ -63,14 +63,6 @@ public static class LogContext static readonly string DataSlotName = typeof(LogContext).FullName; #endif - /// - /// When calling into appdomains without Serilog loaded, e.g. via remoting or during unit testing, - /// it may be necesary to set this value to true so that serialization exceptions are avoided. When possible, - /// using the method in a using block around the call has a lower overhead and - /// should be preferred. - /// - public static bool PermitCrossAppDomainCalls { get; set; } - /// /// Push a property onto the context, returning an /// that can later be used to remove the property, along with any others that @@ -190,6 +182,14 @@ static ImmutableStack Enrichers #endif #if REMOTING + /// + /// When calling into appdomains without Serilog loaded, e.g. via remoting or during unit testing, + /// it may be necesary to set this value to true so that serialization exceptions are avoided. When possible, + /// using the method in a using block around the call has a lower overhead and + /// should be preferred. + /// + public static bool PermitCrossAppDomainCalls { get; set; } + static object GetContext(ImmutableStack value) { var context = !PermitCrossAppDomainCalls ? (object) value : new Wrapper From f036e16d461d26370feb255a480916e707b99c05 Mon Sep 17 00:00:00 2001 From: Colin Young Date: Thu, 28 Jan 2016 19:45:36 -0500 Subject: [PATCH 09/12] Fixing unit tests to work with previous commit. --- test/Serilog.Tests/Context/LogContextTests.cs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/test/Serilog.Tests/Context/LogContextTests.cs b/test/Serilog.Tests/Context/LogContextTests.cs index 48ca526eb..a328a4fd9 100644 --- a/test/Serilog.Tests/Context/LogContextTests.cs +++ b/test/Serilog.Tests/Context/LogContextTests.cs @@ -18,7 +18,9 @@ public class LogContextTests { public LogContextTests() { +#if REMOTING LogContext.PermitCrossAppDomainCalls = false; +#endif #if !ASYNCLOCAL CallContext.LogicalSetData(typeof(LogContext).FullName, null); #endif @@ -113,6 +115,7 @@ public async Task ContextPropertiesCrossAsyncCalls() } } +#if REMOTING [Fact] public async Task ContextPropertiesPersistWhenCrossAppDomainCallsAreEnabled() { @@ -141,6 +144,7 @@ public async Task ContextPropertiesPersistWhenCrossAppDomainCallsAreEnabled() Assert.NotSame(pre, post); } } +#endif #if !NO_APPDOMAIN // Must not actually try to pass context across domains, From 2fd3810e487e6d80c5bf474b98569d98ef76e806 Mon Sep 17 00:00:00 2001 From: Colin Young Date: Tue, 9 Feb 2016 09:54:27 -0500 Subject: [PATCH 10/12] Fixing up framework specifiers and adding support for .Net Standard 1.0 --- src/Serilog.Sinks.Console/project.json | 2 +- src/Serilog/Context/LogContext.cs | 21 +++++++++++++++++++++ src/Serilog/project.json | 2 +- 3 files changed, 23 insertions(+), 2 deletions(-) diff --git a/src/Serilog.Sinks.Console/project.json b/src/Serilog.Sinks.Console/project.json index 7ed4f0806..43cc8364a 100644 --- a/src/Serilog.Sinks.Console/project.json +++ b/src/Serilog.Sinks.Console/project.json @@ -15,7 +15,7 @@ "frameworks": { "net45": { }, - "dotnet5.1": { + "dotnet5.3": { "dependencies": { "System.Console": "4.0.0-beta-23516" } diff --git a/src/Serilog/Context/LogContext.cs b/src/Serilog/Context/LogContext.cs index 958886b13..d724c8edf 100644 --- a/src/Serilog/Context/LogContext.cs +++ b/src/Serilog/Context/LogContext.cs @@ -59,8 +59,13 @@ public static class LogContext { #if ASYNCLOCAL static readonly AsyncLocal> Data = new AsyncLocal>(); +#else +#if DOTNET5_1 + [ThreadStatic] + static ImmutableStack Data; #else static readonly string DataSlotName = typeof(LogContext).FullName; +#endif #endif /// @@ -151,6 +156,21 @@ static ImmutableStack Enrichers Data.Value = GetContext(value); } } +#else + +#if DOTNET5_1 + static ImmutableStack Enrichers + { + get + { + return Data; + } + set + { + Data = GetContext(value); + } + } + #else static ImmutableStack Enrichers { @@ -180,6 +200,7 @@ static ImmutableStack Enrichers } } #endif +#endif #if REMOTING /// diff --git a/src/Serilog/project.json b/src/Serilog/project.json index 51a9aff00..428d4f018 100644 --- a/src/Serilog/project.json +++ b/src/Serilog/project.json @@ -19,7 +19,7 @@ "dotnet5.1": { "compilationOptions": { "keyFile": "../../assets/Serilog.snk", - "define": [ "NO_APPDOMAIN" ] + "define": [ "NO_APPDOMAIN", "LOGCONTEXT" ] }, "dependencies": { "Microsoft.CSharp": "4.0.1-beta-23516", From b3352df0775b9fd2507a34d9db965fa72ac92c6c Mon Sep 17 00:00:00 2001 From: Colin Young Date: Tue, 9 Feb 2016 09:57:56 -0500 Subject: [PATCH 11/12] Missed correcting framework in previous commit. --- src/Serilog.Sinks.Console/project.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Serilog.Sinks.Console/project.json b/src/Serilog.Sinks.Console/project.json index 43cc8364a..7ed4f0806 100644 --- a/src/Serilog.Sinks.Console/project.json +++ b/src/Serilog.Sinks.Console/project.json @@ -15,7 +15,7 @@ "frameworks": { "net45": { }, - "dotnet5.3": { + "dotnet5.1": { "dependencies": { "System.Console": "4.0.0-beta-23516" } From c65dc5b78f71f36fb1d38df08cf75727b6d4f15a Mon Sep 17 00:00:00 2001 From: Colin Young Date: Tue, 9 Feb 2016 21:49:10 -0500 Subject: [PATCH 12/12] Removing LOGCONTEXT feature and #ifdefs --- build.sh | 14 ++++++++++++++ src/Serilog/Context/ImmutableStack.cs | 4 +--- src/Serilog/Context/LogContext.cs | 5 +---- src/Serilog/Enrichers/LogContextEnricher.cs | 2 -- src/Serilog/LoggerConfigurationExtensions.cs | 2 -- src/Serilog/project.json | 6 +++--- test/Serilog.Tests/Context/LogContextTests.cs | 4 +--- test/Serilog.Tests/Settings/AppSettingsTests.cs | 2 -- .../Settings/KeyValuePairSettingsTests.cs | 2 -- test/Serilog.Tests/project.json | 4 ++-- 10 files changed, 22 insertions(+), 23 deletions(-) create mode 100755 build.sh diff --git a/build.sh b/build.sh new file mode 100755 index 000000000..2f97f1ba0 --- /dev/null +++ b/build.sh @@ -0,0 +1,14 @@ +for path in src/*/project.json; do + dirname="$(dirname "${path}")" + dnu restore ${dirname} + dnu build ${dirname} --framework dotnet5.4 --configuration Release --out .\artifacts\testbin; + dnu pack ${dirname} --framework dotnet5.4 --configuration Release --out .\artifacts\packages; +done + +for path in test/*/project.json; do + dirname="$(dirname "${path}")" + dnu restore ${dirname} + dnu build ${dirname} --framework dotnet5.4 --configuration Release --out .\artifacts\testbin; + dnx -p ${dirname} test; +done + diff --git a/src/Serilog/Context/ImmutableStack.cs b/src/Serilog/Context/ImmutableStack.cs index ed67ab198..1e87d2a2c 100644 --- a/src/Serilog/Context/ImmutableStack.cs +++ b/src/Serilog/Context/ImmutableStack.cs @@ -12,7 +12,6 @@ // See the License for the specific language governing permissions and // limitations under the License. -#if LOGCONTEXT using System; using System.Collections.Generic; #if REMOTING @@ -81,5 +80,4 @@ System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator() public T Top => _top; } -} -#endif \ No newline at end of file +} \ No newline at end of file diff --git a/src/Serilog/Context/LogContext.cs b/src/Serilog/Context/LogContext.cs index d724c8edf..26fb50545 100644 --- a/src/Serilog/Context/LogContext.cs +++ b/src/Serilog/Context/LogContext.cs @@ -13,7 +13,6 @@ // limitations under the License. -#if LOGCONTEXT using System; #if REMOTING using System.Runtime.Remoting.Messaging; @@ -260,6 +259,4 @@ sealed class Wrapper : MarshalByRefObject } #endif } -} - -#endif +} \ No newline at end of file diff --git a/src/Serilog/Enrichers/LogContextEnricher.cs b/src/Serilog/Enrichers/LogContextEnricher.cs index 1ecb82fc5..e2432d5af 100644 --- a/src/Serilog/Enrichers/LogContextEnricher.cs +++ b/src/Serilog/Enrichers/LogContextEnricher.cs @@ -12,7 +12,6 @@ // See the License for the specific language governing permissions and // limitations under the License. -#if LOGCONTEXT using Serilog.Context; using Serilog.Core; using Serilog.Events; @@ -27,4 +26,3 @@ public void Enrich(LogEvent logEvent, ILogEventPropertyFactory propertyFactory) } } } -#endif diff --git a/src/Serilog/LoggerConfigurationExtensions.cs b/src/Serilog/LoggerConfigurationExtensions.cs index 04d90b9ec..bca89df6c 100644 --- a/src/Serilog/LoggerConfigurationExtensions.cs +++ b/src/Serilog/LoggerConfigurationExtensions.cs @@ -40,7 +40,6 @@ namespace Serilog public static class LoggerConfigurationExtensions { -#if LOGCONTEXT /// /// Enrich log events with properties from . /// @@ -53,7 +52,6 @@ public static LoggerConfiguration FromLogContext( if (enrichmentConfiguration == null) throw new ArgumentNullException(nameof(enrichmentConfiguration)); return enrichmentConfiguration.With(); } -#endif /// /// Enrich log events with a ThreadId property containing the current . diff --git a/src/Serilog/project.json b/src/Serilog/project.json index 428d4f018..15e1f78b5 100644 --- a/src/Serilog/project.json +++ b/src/Serilog/project.json @@ -10,7 +10,7 @@ "net45": { "compilationOptions": { "keyFile": "../../assets/Serilog.snk", - "define": [ "APPSETTINGS", "LOGCONTEXT", "PROCESS", "FILE_IO", "PERIODIC_BATCHING", "REMOTING" ] + "define": [ "APPSETTINGS", "PROCESS", "FILE_IO", "PERIODIC_BATCHING", "REMOTING" ] }, "frameworkAssemblies": { "System.Configuration": "" @@ -19,7 +19,7 @@ "dotnet5.1": { "compilationOptions": { "keyFile": "../../assets/Serilog.snk", - "define": [ "NO_APPDOMAIN", "LOGCONTEXT" ] + "define": [ "NO_APPDOMAIN" ] }, "dependencies": { "Microsoft.CSharp": "4.0.1-beta-23516", @@ -39,7 +39,7 @@ "dotnet5.4": { "compilationOptions": { "keyFile": "../../assets/Serilog.snk", - "define": [ "ASYNCLOCAL", "LOGCONTEXT", "PROCESS", "FILE_IO", "PERIODIC_BATCHING", "NO_TIMER", "NO_APPDOMAIN", "USERNAMEFROMENV" ] + "define": [ "ASYNCLOCAL", "PROCESS", "FILE_IO", "PERIODIC_BATCHING", "NO_TIMER", "NO_APPDOMAIN", "USERNAMEFROMENV" ] }, "dependencies": { diff --git a/test/Serilog.Tests/Context/LogContextTests.cs b/test/Serilog.Tests/Context/LogContextTests.cs index a328a4fd9..980ad9535 100644 --- a/test/Serilog.Tests/Context/LogContextTests.cs +++ b/test/Serilog.Tests/Context/LogContextTests.cs @@ -1,6 +1,5 @@ using System; using System.IO; -#if LOGCONTEXT using Xunit; using Serilog.Context; using Serilog.Events; @@ -235,5 +234,4 @@ public bool IsCallable() } } #endif -} -#endif +} \ No newline at end of file diff --git a/test/Serilog.Tests/Settings/AppSettingsTests.cs b/test/Serilog.Tests/Settings/AppSettingsTests.cs index be4b6a3cb..ed1aae1ab 100644 --- a/test/Serilog.Tests/Settings/AppSettingsTests.cs +++ b/test/Serilog.Tests/Settings/AppSettingsTests.cs @@ -149,7 +149,6 @@ public void ProcessIdEnricherIsApplied() } #endif -#if LOGCONTEXT [Fact] public void LogContextEnricherIsApplied() { @@ -172,7 +171,6 @@ public void LogContextEnricherIsApplied() Assert.NotNull(evt.Properties["A"].LiteralValue() as int?); Assert.Equal(1, (int)evt.Properties["A"].LiteralValue()); } -#endif } } #endif diff --git a/test/Serilog.Tests/Settings/KeyValuePairSettingsTests.cs b/test/Serilog.Tests/Settings/KeyValuePairSettingsTests.cs index fae6d90bc..714376512 100644 --- a/test/Serilog.Tests/Settings/KeyValuePairSettingsTests.cs +++ b/test/Serilog.Tests/Settings/KeyValuePairSettingsTests.cs @@ -72,9 +72,7 @@ public void FindsEventEnrichersWithinAnAssembly() .ToList(); -#if LOGCONTEXT Assert.True(eventEnrichers.Contains("FromLogContext")); -#endif #if !DOTNET5_1 Assert.True(eventEnrichers.Contains("WithEnvironmentUserName")); Assert.True(eventEnrichers.Contains("WithMachineName")); diff --git a/test/Serilog.Tests/project.json b/test/Serilog.Tests/project.json index c5a5fbfe9..540b93591 100644 --- a/test/Serilog.Tests/project.json +++ b/test/Serilog.Tests/project.json @@ -23,7 +23,7 @@ "dnx452": { "compilationOptions": { "keyFile": "../../assets/Serilog.snk", - "define": [ "APPSETTINGS", "LOGCONTEXT", "PROCESS", "FILE_IO", "PERIODIC_BATCHING", "INTERNAL_TESTS", "REMOTING" ] + "define": [ "APPSETTINGS", "PROCESS", "FILE_IO", "PERIODIC_BATCHING", "INTERNAL_TESTS", "REMOTING" ] }, "frameworkAssemblies": { "System.Configuration": "" @@ -31,7 +31,7 @@ }, "dnxcore50": { "compilationOptions": { - "define": [ "ASYNCLOCAL", "LOGCONTEXT", "FILE_IO", "PERIODIC_BATCHING", "NO_APPDOMAIN" ] + "define": [ "ASYNCLOCAL", "FILE_IO", "PERIODIC_BATCHING", "NO_APPDOMAIN" ] }, "dependencies": { "Microsoft.CSharp": "4.0.1-beta-23516",