From 8232da11a227a0b6792d4e0afc0e6db7814f48ee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Se=CC=81bastien=20BIAUDET?= Date: Sat, 3 Oct 2020 08:50:07 +0200 Subject: [PATCH] Use Microsoft.Extensions.Logging --- src/NEventStore.Example/MainProgram.cs | 15 +- .../NEventStore.Example.csproj | 10 +- ...re.Persistence.AcceptanceTests.Core.csproj | 2 +- .../CommitSequencer.cs | 11 +- .../NEventStore.PollingClient.csproj | 4 +- .../PollingClient2.cs | 7 +- .../MainProgram.cs | 4 +- .../NEventStore.PollingClientExample.csproj | 2 +- ...ore.Serialization.Binary.Core.Tests.csproj | 2 +- ...Store.Serialization.Bson.Core.Tests.csproj | 2 +- .../BsonSerializer.cs | 16 +- ...NEventStore.Serialization.Bson.Core.csproj | 2 +- ...Store.Serialization.GZip.Core.Tests.csproj | 2 +- ...Store.Serialization.Json.Core.Tests.csproj | 2 +- .../JsonSerializer.cs | 20 ++- ...NEventStore.Serialization.Json.Core.csproj | 2 +- ...e.Serialization.Rijndael.Core.Tests.csproj | 2 +- .../NEventStore.Core.Tests.csproj | 4 +- .../EventUpconverterPipelineHook.cs | 5 +- src/NEventStore/EventUpconverterWireup.cs | 12 +- .../Logging/ConsoleWindowLogger.cs | 58 ------- src/NEventStore/Logging/ExtensionMethods.cs | 39 ----- src/NEventStore/Logging/ILog.cs | 151 ------------------ src/NEventStore/Logging/LogFactory.cs | 41 +---- src/NEventStore/Logging/OutputWindowLogger.cs | 66 -------- src/NEventStore/LoggingWireupExtensions.cs | 12 +- src/NEventStore/NEventStore.Core.csproj | 7 +- src/NEventStore/NanoContainer.cs | 27 ++-- src/NEventStore/OptimisticEventStore.cs | 19 +-- src/NEventStore/OptimisticEventStream.cs | 27 ++-- src/NEventStore/OptimisticPipelineHook.cs | 13 +- .../InMemory/InMemoryPersistenceEngine.cs | 37 ++--- .../PipelineHooksAwarePersistanceDecorator.cs | 7 +- src/NEventStore/PersistenceWireup.cs | 13 +- .../PersistenceWireupExtensions.cs | 5 +- .../Serialization/BinarySerializer.cs | 7 +- .../ByteStreamDocumentSerializer.cs | 9 +- .../Serialization/GzipSerializer.cs | 7 +- .../Serialization/RijndaelSerializer.cs | 7 +- src/NEventStore/SerializationWireup.cs | 11 +- .../SerializationWireupExtensions.cs | 7 +- src/NEventStore/Wireup.cs | 5 +- 42 files changed, 191 insertions(+), 510 deletions(-) delete mode 100644 src/NEventStore/Logging/ConsoleWindowLogger.cs delete mode 100644 src/NEventStore/Logging/ExtensionMethods.cs delete mode 100644 src/NEventStore/Logging/ILog.cs delete mode 100644 src/NEventStore/Logging/OutputWindowLogger.cs diff --git a/src/NEventStore.Example/MainProgram.cs b/src/NEventStore.Example/MainProgram.cs index 20b5cca16..2812181d2 100644 --- a/src/NEventStore.Example/MainProgram.cs +++ b/src/NEventStore.Example/MainProgram.cs @@ -3,6 +3,7 @@ namespace NEventStore.Example using System; using NEventStore; using Logging; + using Microsoft.Extensions.Logging; internal static class MainProgram { @@ -12,7 +13,7 @@ internal static class MainProgram private static void Main() { - Console.WindowWidth = Console.LargestWindowWidth - 20; + //Console.WindowWidth = Console.LargestWindowWidth - 20; using (store = WireupEventStore()) { @@ -28,9 +29,17 @@ private static void Main() private static IStoreEvents WireupEventStore() { + + + var loggerFactory = LoggerFactory.Create(logging => { + logging + .AddConsole() + .AddDebug() + .SetMinimumLevel(Microsoft.Extensions.Logging.LogLevel.Trace); + }); + return Wireup.Init() - .LogToOutputWindow(LogLevel.Verbose) - .LogToConsoleWindow(LogLevel.Verbose) + .WithLoggerFactory(loggerFactory) .UseOptimisticPipelineHook() .UsingInMemoryPersistence() .InitializeStorageEngine() diff --git a/src/NEventStore.Example/NEventStore.Example.csproj b/src/NEventStore.Example/NEventStore.Example.csproj index a1a0588d3..b21132fb0 100644 --- a/src/NEventStore.Example/NEventStore.Example.csproj +++ b/src/NEventStore.Example/NEventStore.Example.csproj @@ -1,7 +1,7 @@  - netcoreapp2.0;net45 + netcoreapp2.0;net461 false exe @@ -13,7 +13,7 @@ TRACE;DEBUG;NETSTANDARD2_0 NETSTANDARD2_0 - + TRACE;DEBUG @@ -26,4 +26,10 @@ + + + + + + diff --git a/src/NEventStore.Persistence.AcceptanceTests/NEventStore.Persistence.AcceptanceTests.Core.csproj b/src/NEventStore.Persistence.AcceptanceTests/NEventStore.Persistence.AcceptanceTests.Core.csproj index 717c273f4..6ce18d999 100644 --- a/src/NEventStore.Persistence.AcceptanceTests/NEventStore.Persistence.AcceptanceTests.Core.csproj +++ b/src/NEventStore.Persistence.AcceptanceTests/NEventStore.Persistence.AcceptanceTests.Core.csproj @@ -1,6 +1,6 @@  - netcoreapp2.0;net45 + netcoreapp2.0;net461 false NEventStore.Persistence.AcceptanceTests false diff --git a/src/NEventStore.PollingClient/CommitSequencer.cs b/src/NEventStore.PollingClient/CommitSequencer.cs index 9639416c3..9c0dcbc2c 100644 --- a/src/NEventStore.PollingClient/CommitSequencer.cs +++ b/src/NEventStore.PollingClient/CommitSequencer.cs @@ -1,4 +1,5 @@ using System; +using Microsoft.Extensions.Logging; using NEventStore.Helpers; using NEventStore.Logging; @@ -6,7 +7,7 @@ namespace NEventStore.PollingClient { public class CommitSequencer { - private readonly ILog _logger; + private readonly ILogger _logger; private readonly Func _commitCallback; @@ -34,13 +35,13 @@ public PollingClient2.HandlingResult Handle(ICommit commit) } else if (_lastCommitRead >= lc) { - if (_logger.IsWarnEnabled) _logger.Warn(String.Format("Wrong sequence in commit, last read {0} actual read {1}", _lastCommitRead, lc)); + _logger.LogWarning(String.Format("Wrong sequence in commit, last read {0} actual read {1}", _lastCommitRead, lc)); return PollingClient2.HandlingResult.MoveToNext; } if (outOfSequenceTimestamp == null) { - if (_logger.IsDebugEnabled) _logger.Debug("Sequencer found out of sequence, last dispatched {0} now dispatching {1}", _lastCommitRead, lc); + _logger.LogDebug("Sequencer found out of sequence, last dispatched {0} now dispatching {1}", _lastCommitRead, lc); outOfSequenceTimestamp = DateTimeService.Now; } else @@ -48,10 +49,10 @@ public PollingClient2.HandlingResult Handle(ICommit commit) var interval = DateTimeService.Now.Subtract(outOfSequenceTimestamp.Value); if (interval.TotalMilliseconds > _outOfSequenceTimeoutInMilliseconds) { - if (_logger.IsDebugEnabled) _logger.Debug("Sequencer out of sequence timeout after {0} ms, last dispatched {1} now dispatching {2}", interval.TotalMilliseconds, _lastCommitRead, lc); + _logger.LogDebug("Sequencer out of sequence timeout after {0} ms, last dispatched {1} now dispatching {2}", interval.TotalMilliseconds, _lastCommitRead, lc); return InnerHandleResult(commit, lc); } - if (_logger.IsDebugEnabled) _logger.Debug("Sequencer still out of sequence from {0} ms, last dispatched {1} now dispatching {2}", interval.TotalMilliseconds, _lastCommitRead, lc); + _logger.LogDebug("Sequencer still out of sequence from {0} ms, last dispatched {1} now dispatching {2}", interval.TotalMilliseconds, _lastCommitRead, lc); } return PollingClient2.HandlingResult.Retry; diff --git a/src/NEventStore.PollingClient/NEventStore.PollingClient.csproj b/src/NEventStore.PollingClient/NEventStore.PollingClient.csproj index 00978faa9..172fd6e0f 100644 --- a/src/NEventStore.PollingClient/NEventStore.PollingClient.csproj +++ b/src/NEventStore.PollingClient/NEventStore.PollingClient.csproj @@ -1,6 +1,6 @@  - netstandard2.0;net45 + netstandard2.0;net461 false NEventStore.PollingClient NEventStore.PollingClient @@ -19,7 +19,7 @@ TRACE;DEBUG;NETSTANDARD2_0 NETSTANDARD2_0 - + TRACE;DEBUG diff --git a/src/NEventStore.PollingClient/PollingClient2.cs b/src/NEventStore.PollingClient/PollingClient2.cs index 1be2690d7..4fd9c38db 100644 --- a/src/NEventStore.PollingClient/PollingClient2.cs +++ b/src/NEventStore.PollingClient/PollingClient2.cs @@ -4,6 +4,7 @@ using NEventStore.Logging; using NEventStore.Persistence; using System.Collections.Concurrent; +using Microsoft.Extensions.Logging; namespace NEventStore.PollingClient { @@ -19,7 +20,7 @@ public enum HandlingResult Stop = 2, } - private readonly ILog _logger; + private readonly ILogger _logger; private readonly Func _commitCallback; @@ -190,7 +191,7 @@ private bool InnerPoll() var result = _commitCallback(commit); if (result == HandlingResult.Retry) { - if (_logger.IsVerboseEnabled) _logger.Verbose("Commit callback ask retry for checkpointToken {0} - last dispatched {1}", commit.CheckpointToken, _checkpointToken); + _logger.LogTrace("Commit callback ask retry for checkpointToken {0} - last dispatched {1}", commit.CheckpointToken, _checkpointToken); break; } else if (result == HandlingResult.Stop) @@ -211,7 +212,7 @@ private bool InnerPoll() // These exceptions are expected to be transient, we log at maximum a log each minute. if (DateTime.UtcNow.Subtract(_lastPollingErrorLogTimestamp).TotalMinutes > 1) { - if (_logger.IsErrorEnabled) _logger.Error(String.Format("Error during polling client {0}", ex.ToString())); + _logger.LogError(String.Format("Error during polling client {0}", ex.ToString())); _lastPollingErrorLogTimestamp = DateTime.UtcNow; } diff --git a/src/NEventStore.PollingClientExample/MainProgram.cs b/src/NEventStore.PollingClientExample/MainProgram.cs index 6f609fb86..bdb1a69f0 100644 --- a/src/NEventStore.PollingClientExample/MainProgram.cs +++ b/src/NEventStore.PollingClientExample/MainProgram.cs @@ -52,8 +52,8 @@ private static void SaveCheckpoint(Int64 checkpointToken) private static IStoreEvents WireupEventStore() { return Wireup.Init() - .LogToOutputWindow(LogLevel.Verbose) - .LogToConsoleWindow(LogLevel.Verbose) + //.LogToOutputWindow(LogLevel.Verbose) + //.LogToConsoleWindow(LogLevel.Verbose) .UsingInMemoryPersistence() .InitializeStorageEngine() #if !NETSTANDARD1_6 && !NETSTANDARD2_0 diff --git a/src/NEventStore.PollingClientExample/NEventStore.PollingClientExample.csproj b/src/NEventStore.PollingClientExample/NEventStore.PollingClientExample.csproj index d26c41882..06f782f73 100644 --- a/src/NEventStore.PollingClientExample/NEventStore.PollingClientExample.csproj +++ b/src/NEventStore.PollingClientExample/NEventStore.PollingClientExample.csproj @@ -1,7 +1,7 @@  - netcoreapp2.0;net45 + netcoreapp2.0;net461 false exe diff --git a/src/NEventStore.Serialization.Binary.Tests/NEventStore.Serialization.Binary.Core.Tests.csproj b/src/NEventStore.Serialization.Binary.Tests/NEventStore.Serialization.Binary.Core.Tests.csproj index 1dc3f221e..d14fa4bae 100644 --- a/src/NEventStore.Serialization.Binary.Tests/NEventStore.Serialization.Binary.Core.Tests.csproj +++ b/src/NEventStore.Serialization.Binary.Tests/NEventStore.Serialization.Binary.Core.Tests.csproj @@ -1,7 +1,7 @@  - netcoreapp2.0;net45 + netcoreapp2.0;net461 false exe diff --git a/src/NEventStore.Serialization.Bson.Tests/NEventStore.Serialization.Bson.Core.Tests.csproj b/src/NEventStore.Serialization.Bson.Tests/NEventStore.Serialization.Bson.Core.Tests.csproj index bd3018832..b76785276 100644 --- a/src/NEventStore.Serialization.Bson.Tests/NEventStore.Serialization.Bson.Core.Tests.csproj +++ b/src/NEventStore.Serialization.Bson.Tests/NEventStore.Serialization.Bson.Core.Tests.csproj @@ -1,7 +1,7 @@  - netcoreapp2.0;net45 + netcoreapp2.0;net461 false exe diff --git a/src/NEventStore.Serialization.Bson/BsonSerializer.cs b/src/NEventStore.Serialization.Bson/BsonSerializer.cs index 854749789..6cab887ae 100644 --- a/src/NEventStore.Serialization.Bson/BsonSerializer.cs +++ b/src/NEventStore.Serialization.Bson/BsonSerializer.cs @@ -9,10 +9,11 @@ namespace NEventStore.Serialization.Bson using System.Collections.Generic; using Newtonsoft.Json; using System.Linq; + using Microsoft.Extensions.Logging; public class BsonSerializer : ISerialize { - private static readonly ILog Logger = LogFactory.BuildLogger(typeof(BsonSerializer)); + private static readonly ILogger Logger = LogFactory.BuildLogger(typeof(BsonSerializer)); private readonly IEnumerable _knownTypes = new[] { typeof(List), typeof(Dictionary) }; @@ -39,12 +40,9 @@ public BsonSerializer(params Type[] knownTypes) _knownTypes = knownTypes ?? _knownTypes; - if (Logger.IsDebugEnabled) + foreach (var type in _knownTypes) { - foreach (var type in _knownTypes) - { - Logger.Debug(Messages.RegisteringKnownType, type); - } + Logger.LogDebug(Messages.RegisteringKnownType, type); } } @@ -79,11 +77,11 @@ protected virtual Newtonsoft.Json.JsonSerializer GetSerializer(Type typeToSerial { if (_knownTypes.Contains(typeToSerialize)) { - if (Logger.IsVerboseEnabled) Logger.Verbose(Messages.UsingUntypedSerializer, typeToSerialize); + Logger.LogTrace(Messages.UsingUntypedSerializer, typeToSerialize); return _untypedSerializer; } - if (Logger.IsVerboseEnabled) Logger.Verbose(Messages.UsingTypedSerializer, typeToSerialize); + Logger.LogTrace(Messages.UsingTypedSerializer, typeToSerialize); return _typedSerializer; } @@ -95,7 +93,7 @@ private static bool IsArray(Type type) bool array = typeof(IEnumerable).GetTypeInfo().IsAssignableFrom(type) && !typeof(IDictionary).GetTypeInfo().IsAssignableFrom(type); #endif - if (Logger.IsVerboseEnabled) Logger.Verbose(Messages.TypeIsArray, type, array); + Logger.LogTrace(Messages.TypeIsArray, type, array); return array; } diff --git a/src/NEventStore.Serialization.Bson/NEventStore.Serialization.Bson.Core.csproj b/src/NEventStore.Serialization.Bson/NEventStore.Serialization.Bson.Core.csproj index a42247203..274b56535 100644 --- a/src/NEventStore.Serialization.Bson/NEventStore.Serialization.Bson.Core.csproj +++ b/src/NEventStore.Serialization.Bson/NEventStore.Serialization.Bson.Core.csproj @@ -1,6 +1,6 @@  - netstandard2.0;net45 + netstandard2.0;net461 false NEventStore.Serialization.Bson NEventStore.Serialization.Bson diff --git a/src/NEventStore.Serialization.Gzip.Tests/NEventStore.Serialization.GZip.Core.Tests.csproj b/src/NEventStore.Serialization.Gzip.Tests/NEventStore.Serialization.GZip.Core.Tests.csproj index ec51ba62e..5c7f18ead 100644 --- a/src/NEventStore.Serialization.Gzip.Tests/NEventStore.Serialization.GZip.Core.Tests.csproj +++ b/src/NEventStore.Serialization.Gzip.Tests/NEventStore.Serialization.GZip.Core.Tests.csproj @@ -1,7 +1,7 @@  - netcoreapp2.0;net45 + netcoreapp2.0;net461 false exe diff --git a/src/NEventStore.Serialization.Json.Tests/NEventStore.Serialization.Json.Core.Tests.csproj b/src/NEventStore.Serialization.Json.Tests/NEventStore.Serialization.Json.Core.Tests.csproj index fa2644d53..2ee9c6db0 100644 --- a/src/NEventStore.Serialization.Json.Tests/NEventStore.Serialization.Json.Core.Tests.csproj +++ b/src/NEventStore.Serialization.Json.Tests/NEventStore.Serialization.Json.Core.Tests.csproj @@ -1,7 +1,7 @@  - netcoreapp2.0;net45 + netcoreapp2.0;net461 false exe diff --git a/src/NEventStore.Serialization.Json/JsonSerializer.cs b/src/NEventStore.Serialization.Json/JsonSerializer.cs index 247f5768d..0fb1b93cd 100644 --- a/src/NEventStore.Serialization.Json/JsonSerializer.cs +++ b/src/NEventStore.Serialization.Json/JsonSerializer.cs @@ -7,10 +7,11 @@ namespace NEventStore.Serialization.Json using System.Text; using Newtonsoft.Json; using NEventStore.Logging; + using Microsoft.Extensions.Logging; public class JsonSerializer : ISerialize { - private static readonly ILog Logger = LogFactory.BuildLogger(typeof(JsonSerializer)); + private static readonly ILogger Logger = LogFactory.BuildLogger(typeof(JsonSerializer)); private readonly IEnumerable _knownTypes = new[] { typeof(List), typeof(Dictionary) }; @@ -36,19 +37,16 @@ public JsonSerializer(params Type[] knownTypes) } _knownTypes = knownTypes ?? _knownTypes; - - if (Logger.IsDebugEnabled) + + foreach (var type in _knownTypes) { - foreach (var type in _knownTypes) - { - Logger.Debug(Messages.RegisteringKnownType, type); - } + Logger.LogDebug(Messages.RegisteringKnownType, type); } } public virtual void Serialize(Stream output, T graph) { - if (Logger.IsVerboseEnabled) Logger.Verbose(Messages.SerializingGraph, typeof(T)); + Logger.LogTrace(Messages.SerializingGraph, typeof(T)); using (var streamWriter = new StreamWriter(output, Encoding.UTF8)) using (var jsonTextWriter = new JsonTextWriter(streamWriter)) { @@ -58,7 +56,7 @@ public virtual void Serialize(Stream output, T graph) public virtual T Deserialize(Stream input) { - if (Logger.IsVerboseEnabled) Logger.Verbose(Messages.DeserializingStream, typeof(T)); + Logger.LogTrace(Messages.DeserializingStream, typeof(T)); using (var streamReader = new StreamReader(input, Encoding.UTF8)) using (var jsonTextReader = new JsonTextReader(streamReader)) { @@ -81,11 +79,11 @@ protected virtual Newtonsoft.Json.JsonSerializer GetSerializer(Type typeToSerial { if (_knownTypes.Contains(typeToSerialize)) { - if (Logger.IsVerboseEnabled) Logger.Verbose(Messages.UsingUntypedSerializer, typeToSerialize); + Logger.LogTrace(Messages.UsingUntypedSerializer, typeToSerialize); return _untypedSerializer; } - if (Logger.IsVerboseEnabled) Logger.Verbose(Messages.UsingTypedSerializer, typeToSerialize); + Logger.LogTrace(Messages.UsingTypedSerializer, typeToSerialize); return _typedSerializer; } } diff --git a/src/NEventStore.Serialization.Json/NEventStore.Serialization.Json.Core.csproj b/src/NEventStore.Serialization.Json/NEventStore.Serialization.Json.Core.csproj index b11e96b46..b68bdd845 100644 --- a/src/NEventStore.Serialization.Json/NEventStore.Serialization.Json.Core.csproj +++ b/src/NEventStore.Serialization.Json/NEventStore.Serialization.Json.Core.csproj @@ -1,6 +1,6 @@  - netstandard2.0;net45 + netstandard2.0;net461 false NEventStore.Serialization.Json NEventStore.Serialization.Json diff --git a/src/NEventStore.Serialization.Rijndael.Tests/NEventStore.Serialization.Rijndael.Core.Tests.csproj b/src/NEventStore.Serialization.Rijndael.Tests/NEventStore.Serialization.Rijndael.Core.Tests.csproj index 5334ab96b..9af4e1a2e 100644 --- a/src/NEventStore.Serialization.Rijndael.Tests/NEventStore.Serialization.Rijndael.Core.Tests.csproj +++ b/src/NEventStore.Serialization.Rijndael.Tests/NEventStore.Serialization.Rijndael.Core.Tests.csproj @@ -1,7 +1,7 @@  - netcoreapp2.0;net45 + netcoreapp2.0;net461 false exe diff --git a/src/NEventStore.Tests/NEventStore.Core.Tests.csproj b/src/NEventStore.Tests/NEventStore.Core.Tests.csproj index 92507c993..0ce57e93a 100644 --- a/src/NEventStore.Tests/NEventStore.Core.Tests.csproj +++ b/src/NEventStore.Tests/NEventStore.Core.Tests.csproj @@ -1,7 +1,7 @@  - netcoreapp2.0;net45 + netcoreapp2.0;net461 false false NEventStore.Tests @@ -12,7 +12,7 @@ TRACE;DEBUG;NUNIT;NETSTANDARD2_0 NUNIT;NETSTANDARD2_0 - + TRACE;DEBUG;NUNIT NUNIT diff --git a/src/NEventStore/Conversion/EventUpconverterPipelineHook.cs b/src/NEventStore/Conversion/EventUpconverterPipelineHook.cs index 0dd6eea2e..059a2cf47 100644 --- a/src/NEventStore/Conversion/EventUpconverterPipelineHook.cs +++ b/src/NEventStore/Conversion/EventUpconverterPipelineHook.cs @@ -3,12 +3,13 @@ namespace NEventStore.Conversion using System; using System.Collections.Generic; using System.Linq; + using Microsoft.Extensions.Logging; using NEventStore.Logging; using NEventStore.Persistence; public class EventUpconverterPipelineHook : PipelineHookBase { - private static readonly ILog Logger = LogFactory.BuildLogger(typeof(EventUpconverterPipelineHook)); + private static readonly ILogger Logger = LogFactory.BuildLogger(typeof(EventUpconverterPipelineHook)); private readonly IDictionary> _converters; public EventUpconverterPipelineHook(IDictionary> converters) @@ -61,7 +62,7 @@ private object Convert(object source) } object target = converter(source); - if (Logger.IsDebugEnabled) Logger.Debug(Resources.ConvertingEvent, source.GetType(), target.GetType()); + Logger.LogDebug(Resources.ConvertingEvent, source.GetType(), target.GetType()); return Convert(target); } diff --git a/src/NEventStore/EventUpconverterWireup.cs b/src/NEventStore/EventUpconverterWireup.cs index 3a5fc1d9e..c0c8c08de 100644 --- a/src/NEventStore/EventUpconverterWireup.cs +++ b/src/NEventStore/EventUpconverterWireup.cs @@ -4,18 +4,19 @@ namespace NEventStore using System.Collections.Generic; using System.Linq; using System.Reflection; + using Microsoft.Extensions.Logging; using NEventStore.Conversion; using NEventStore.Logging; public class EventUpconverterWireup : Wireup { - private static readonly ILog Logger = LogFactory.BuildLogger(typeof(EventUpconverterWireup)); + private static readonly ILogger Logger = LogFactory.BuildLogger(typeof(EventUpconverterWireup)); private readonly List _assembliesToScan = new List(); private readonly IDictionary> _registered = new Dictionary>(); public EventUpconverterWireup(Wireup wireup) : base(wireup) { - if (Logger.IsDebugEnabled) Logger.Debug(Messages.EventUpconverterRegistered); + Logger.LogDebug(Messages.EventUpconverterRegistered); Container.Register(_ => { @@ -89,11 +90,10 @@ from t in a.GetTypes() public virtual EventUpconverterWireup WithConvertersFrom(params Assembly[] assemblies) { - if (Logger.IsDebugEnabled) - { - Logger.Debug(Messages.EventUpconvertersLoadedFrom, + + + Logger.LogDebug(Messages.EventUpconvertersLoadedFrom, string.Join(", ", assemblies.Select(a => $"{a.GetName().Name} {a.GetName().Version}"))); - } _assembliesToScan.AddRange(assemblies); return this; } diff --git a/src/NEventStore/Logging/ConsoleWindowLogger.cs b/src/NEventStore/Logging/ConsoleWindowLogger.cs deleted file mode 100644 index 78c7c9d1d..000000000 --- a/src/NEventStore/Logging/ConsoleWindowLogger.cs +++ /dev/null @@ -1,58 +0,0 @@ -namespace NEventStore.Logging -{ - using System; - - public class ConsoleWindowLogger : NEventStoreBaseLogger - { - private static readonly object Sync = new object(); - private readonly ConsoleColor _originalColor = Console.ForegroundColor; - private readonly Type _typeToLog; - - public int MyProperty { get; set; } - - public ConsoleWindowLogger(Type typeToLog, LogLevel logLevel = LogLevel.Info) : base (logLevel) - { - _typeToLog = typeToLog; - } - - public override void Verbose(string message, params object[] values) - { - Log(ConsoleColor.DarkGreen, message, values); - } - - public override void Debug(string message, params object[] values) - { - Log(ConsoleColor.Green, message, values); - } - - public override void Info(string message, params object[] values) - { - Log(ConsoleColor.White, message, values); - } - - public override void Warn(string message, params object[] values) - { - Log(ConsoleColor.Yellow, message, values); - } - - public override void Error(string message, params object[] values) - { - Log(ConsoleColor.DarkRed, message, values); - } - - public override void Fatal(string message, params object[] values) - { - Log(ConsoleColor.Red, message, values); - } - - private void Log(ConsoleColor color, string message, params object[] values) - { - lock (Sync) - { - Console.ForegroundColor = color; - Console.WriteLine(message.FormatMessage(_typeToLog, values)); - Console.ForegroundColor = _originalColor; - } - } - } -} \ No newline at end of file diff --git a/src/NEventStore/Logging/ExtensionMethods.cs b/src/NEventStore/Logging/ExtensionMethods.cs deleted file mode 100644 index a37d84ab4..000000000 --- a/src/NEventStore/Logging/ExtensionMethods.cs +++ /dev/null @@ -1,39 +0,0 @@ -namespace NEventStore.Logging -{ - using System; - using System.Globalization; - using System.Threading; - - internal static class ExtensionMethods - { - private const string MessageFormat = "{0:yyyy/MM/dd HH:mm:ss.ff} - {1} - {2} - {3}"; - - public static string FormatMessage(this string message, Type typeToLog, params object[] values) - { - String formattedMessage; - if (values == null || values.Length == 0) - { - //no parameters no need to string format - formattedMessage = message; - } - else - { - formattedMessage = string.Format(CultureInfo.InvariantCulture, message, values); - } - return string.Format( - CultureInfo.InvariantCulture, - MessageFormat, - SystemTime.UtcNow, - Thread.CurrentThread.GetName(), - typeToLog.FullName, - formattedMessage); - } - - private static string GetName(this Thread thread) - { - return !string.IsNullOrEmpty(thread.Name) - ? thread.Name - : thread.ManagedThreadId.ToString(CultureInfo.InvariantCulture); - } - } -} \ No newline at end of file diff --git a/src/NEventStore/Logging/ILog.cs b/src/NEventStore/Logging/ILog.cs deleted file mode 100644 index 162d7d577..000000000 --- a/src/NEventStore/Logging/ILog.cs +++ /dev/null @@ -1,151 +0,0 @@ -namespace NEventStore.Logging -{ - /// - /// Indicates the ability to log diagnostic information. - /// - /// - /// Object instances which implement this interface must be designed to be multi-thread safe. - /// The logging class is intended to be very simple and fast, so all the checks to see if the - /// desired logging level is supported should be done in code. - /// This logging class is not a fully featured logging framework and is intended to be used - /// only within the NEventStore project. - /// - public interface ILog - { - /// - /// Is true if the logger has verbose level enabled - /// - bool IsVerboseEnabled { get; } - - /// - /// Is true if the logger has debug level enabled - /// - bool IsDebugEnabled { get; } - - /// - /// Is true if the logger has info level enabled - /// - bool IsInfoEnabled { get; } - - /// - /// Is true if the logger has warn level enabled - /// - bool IsWarnEnabled { get; } - - /// - /// Is true if the logger has error level enabled - /// - bool IsErrorEnabled { get; } - - /// - /// Is true if the logger has fatal level enabled - /// - bool IsFatalEnabled { get; } - - /// - /// Level of the logger - /// - LogLevel LogLevel { get; } - - /// - /// Logs the most detailed level of diagnostic information. - /// - /// The diagnostic message to be logged. - /// All parameter to be formatted into the message, if any. - void Verbose(string message, params object[] values); - - /// - /// Logs the debug-level diagnostic information. - /// - /// The diagnostic message to be logged. - /// All parameter to be formatted into the message, if any. - void Debug(string message, params object[] values); - - /// - /// Logs important runtime diagnostic information. - /// - /// The diagnostic message to be logged. - /// All parameter to be formatted into the message, if any. - void Info(string message, params object[] values); - - /// - /// Logs diagnostic issues to which attention should be paid. - /// - /// The diagnostic message to be logged. - /// All parameter to be formatted into the message, if any. - void Warn(string message, params object[] values); - - /// - /// Logs application and infrastructure-level errors. - /// - /// The diagnostic message to be logged. - /// All parameter to be formatted into the message, if any. - void Error(string message, params object[] values); - - /// - /// Logs fatal errors which result in process termination. - /// - /// The diagnostic message to be logged. - /// All parameter to be formatted into the message, if any. - void Fatal(string message, params object[] values); - } - - public abstract class NEventStoreBaseLogger : ILog - { - private LogLevel _logLevel; - - public LogLevel LogLevel - { - get => _logLevel; - private set - { - _logLevel = value; - IsVerboseEnabled = _logLevel <= LogLevel.Verbose; - IsDebugEnabled = _logLevel <= LogLevel.Debug; - IsInfoEnabled = _logLevel <= LogLevel.Info; - IsWarnEnabled = _logLevel <= LogLevel.Warn; - IsErrorEnabled = _logLevel <= LogLevel.Error; - IsFatalEnabled = _logLevel <= LogLevel.Fatal; - } - } - - public NEventStoreBaseLogger(LogLevel logLevel) - { - LogLevel = logLevel; - } - - public bool IsVerboseEnabled { get; private set; } - - public bool IsDebugEnabled { get; private set; } - - public bool IsInfoEnabled { get; private set; } - - public bool IsWarnEnabled { get; private set; } - - public bool IsErrorEnabled { get; private set; } - - public bool IsFatalEnabled { get; private set; } - - public abstract void Debug(string message, params object[] values); - - public abstract void Error(string message, params object[] values); - - public abstract void Fatal(string message, params object[] values); - - public abstract void Info(string message, params object[] values); - - public abstract void Verbose(string message, params object[] values); - - public abstract void Warn(string message, params object[] values); - } - - public enum LogLevel - { - Verbose = 0, - Debug = 1, - Info = 2, - Warn = 3, - Error = 4, - Fatal = 5 - } -} \ No newline at end of file diff --git a/src/NEventStore/Logging/LogFactory.cs b/src/NEventStore/Logging/LogFactory.cs index 91ecb3be9..70529d6d0 100644 --- a/src/NEventStore/Logging/LogFactory.cs +++ b/src/NEventStore/Logging/LogFactory.cs @@ -1,6 +1,8 @@ namespace NEventStore.Logging { using System; + using Microsoft.Extensions.Logging; + using Microsoft.Extensions.Logging.Abstractions; /// /// Provides the ability to get a new instance of the configured logger. @@ -12,48 +14,13 @@ public static class LogFactory /// static LogFactory() { - var logger = new NullLogger(); + var logger = NullLogger.Instance; BuildLogger = type => logger; } /// /// Gets or sets the log builder of the configured logger. This should be invoked to return a new logging instance. /// - public static Func BuildLogger { get; set; } - - private class NullLogger : ILog - { - public bool IsVerboseEnabled => false; - - public bool IsDebugEnabled => false; - - public bool IsInfoEnabled => false; - - public bool IsWarnEnabled => false; - - public bool IsErrorEnabled => false; - - public bool IsFatalEnabled => false; - - public LogLevel LogLevel => LogLevel.Fatal; - - public void Verbose(string message, params object[] values) - { } - - public void Debug(string message, params object[] values) - { } - - public void Info(string message, params object[] values) - { } - - public void Warn(string message, params object[] values) - { } - - public void Error(string message, params object[] values) - { } - - public void Fatal(string message, params object[] values) - { } - } + public static Func BuildLogger { get; set; } } } \ No newline at end of file diff --git a/src/NEventStore/Logging/OutputWindowLogger.cs b/src/NEventStore/Logging/OutputWindowLogger.cs deleted file mode 100644 index b179cc227..000000000 --- a/src/NEventStore/Logging/OutputWindowLogger.cs +++ /dev/null @@ -1,66 +0,0 @@ -namespace NEventStore.Logging -{ - using System; - using System.Diagnostics; - - public class OutputWindowLogger : NEventStoreBaseLogger - { - private static readonly object Sync = new object(); - private readonly Type _typeToLog; - - public OutputWindowLogger(Type typeToLog, LogLevel logLevel = LogLevel.Info) : base(logLevel) - { - _typeToLog = typeToLog; - } - - public override void Verbose(string message, params object[] values) - { - DebugWindow("Verbose", message, values); - } - - public override void Debug(string message, params object[] values) - { - DebugWindow("Debug", message, values); - } - - public override void Info(string message, params object[] values) - { - TraceWindow("Info", message, values); - } - - public override void Warn(string message, params object[] values) - { - TraceWindow("Warn", message, values); - } - - public override void Error(string message, params object[] values) - { - TraceWindow("Error", message, values); - } - - public override void Fatal(string message, params object[] values) - { - TraceWindow("Fatal", message, values); - } - - protected virtual void DebugWindow(string category, string message, params object[] values) - { - lock (Sync) - { - System.Diagnostics.Debug.WriteLine(category, message.FormatMessage(_typeToLog, values)); - } - } - - protected virtual void TraceWindow(string category, string message, params object[] values) - { - lock (Sync) - { -#if !NETSTANDARD1_6 - Trace.WriteLine(category, message.FormatMessage(_typeToLog, values)); -#else - System.Diagnostics.Debug.WriteLine(category, message.FormatMessage(_typeToLog, values)); -#endif - } - } - } -} \ No newline at end of file diff --git a/src/NEventStore/LoggingWireupExtensions.cs b/src/NEventStore/LoggingWireupExtensions.cs index c3f3fe455..a48e0859e 100644 --- a/src/NEventStore/LoggingWireupExtensions.cs +++ b/src/NEventStore/LoggingWireupExtensions.cs @@ -1,21 +1,17 @@ namespace NEventStore { using System; + using Microsoft.Extensions.Logging; using NEventStore.Logging; public static class LoggingWireupExtensions { - public static Wireup LogToConsoleWindow(this Wireup wireup, LogLevel logLevel = LogLevel.Info) + public static Wireup WithLoggerFactory(this Wireup wireup, ILoggerFactory loggerFactory) { - return wireup.LogTo(type => new ConsoleWindowLogger(type, logLevel)); + return wireup.LogTo(type => loggerFactory.CreateLogger(type)); } - public static Wireup LogToOutputWindow(this Wireup wireup, LogLevel logLevel = LogLevel.Info) - { - return wireup.LogTo(type => new OutputWindowLogger(type, logLevel)); - } - - public static Wireup LogTo(this Wireup wireup, Func logger) + public static Wireup LogTo(this Wireup wireup, Func logger) { LogFactory.BuildLogger = logger; return wireup; diff --git a/src/NEventStore/NEventStore.Core.csproj b/src/NEventStore/NEventStore.Core.csproj index 4c175ae9a..b9065bfd6 100644 --- a/src/NEventStore/NEventStore.Core.csproj +++ b/src/NEventStore/NEventStore.Core.csproj @@ -1,6 +1,6 @@  - netstandard2.0;net45 + netstandard2.0;net461 false NEventStore NEventStore @@ -20,9 +20,12 @@ TRACE;DEBUG;NETSTANDARD2_0 NETSTANDARD2_0 - + TRACE;DEBUG + + + diff --git a/src/NEventStore/NanoContainer.cs b/src/NEventStore/NanoContainer.cs index 22898bdf6..431e179a2 100644 --- a/src/NEventStore/NanoContainer.cs +++ b/src/NEventStore/NanoContainer.cs @@ -4,10 +4,11 @@ namespace NEventStore using System.Collections.Generic; using NEventStore.Logging; using System.Reflection; + using Microsoft.Extensions.Logging; public class NanoContainer { - private static readonly ILog Logger = LogFactory.BuildLogger(typeof(NanoContainer)); + private static readonly ILogger Logger = LogFactory.BuildLogger(typeof(NanoContainer)); private readonly IDictionary _registrations = new Dictionary(); @@ -15,7 +16,7 @@ public class NanoContainer public virtual ContainerRegistration Register(Func resolve) where TService : class { - if (Logger.IsDebugEnabled) Logger.Debug(Messages.RegisteringWireupCallback, typeof(TService)); + Logger.LogDebug(Messages.RegisteringWireupCallback, typeof(TService)); var registration = new ContainerRegistration(c => (object)resolve(c)); _registrations[typeof(TService)] = registration; return registration; @@ -40,7 +41,7 @@ public virtual ContainerRegistration Register(TService instance) } #endif - if (Logger.IsDebugEnabled) Logger.Debug(Messages.RegisteringServiceInstance, typeof(TService)); + Logger.LogDebug(Messages.RegisteringServiceInstance, typeof(TService)); var registration = new ContainerRegistration(instance); _registrations[typeof(TService)] = registration; return registration; @@ -48,61 +49,61 @@ public virtual ContainerRegistration Register(TService instance) public virtual TService Resolve() { - if (Logger.IsDebugEnabled) Logger.Debug(Messages.ResolvingService, typeof(TService)); + Logger.LogDebug(Messages.ResolvingService, typeof(TService)); if (_registrations.TryGetValue(typeof(TService), out ContainerRegistration registration)) { return (TService)registration.Resolve(this); } - if (Logger.IsDebugEnabled) Logger.Debug(Messages.UnableToResolve, typeof(TService)); + Logger.LogDebug(Messages.UnableToResolve, typeof(TService)); return default(TService); } } public class ContainerRegistration { - private static readonly ILog Logger = LogFactory.BuildLogger(typeof(ContainerRegistration)); + private static readonly ILogger Logger = LogFactory.BuildLogger(typeof(ContainerRegistration)); private readonly Func _resolve; private object _instance; private bool _instancePerCall; public ContainerRegistration(Func resolve) { - if (Logger.IsVerboseEnabled) Logger.Verbose(Messages.AddingWireupCallback); + Logger.LogInformation(Messages.AddingWireupCallback); _resolve = resolve; } public ContainerRegistration(object instance) { - if (Logger.IsVerboseEnabled) Logger.Verbose(Messages.AddingWireupRegistration, instance.GetType()); + Logger.LogTrace(Messages.AddingWireupRegistration, instance.GetType()); _instance = instance; } public virtual ContainerRegistration InstancePerCall() { - if (Logger.IsVerboseEnabled) Logger.Verbose(Messages.ConfiguringInstancePerCall); + Logger.LogTrace(Messages.ConfiguringInstancePerCall); _instancePerCall = true; return this; } public virtual object Resolve(NanoContainer container) { - if (Logger.IsVerboseEnabled) Logger.Verbose(Messages.ResolvingInstance); + Logger.LogTrace(Messages.ResolvingInstance); if (_instancePerCall) { - if (Logger.IsVerboseEnabled) Logger.Verbose(Messages.BuildingNewInstance); + Logger.LogTrace(Messages.BuildingNewInstance); return _resolve(container); } - if (Logger.IsVerboseEnabled) Logger.Verbose(Messages.AttemptingToResolveInstance); + Logger.LogTrace(Messages.AttemptingToResolveInstance); if (_instance != null) { return _instance; } - if (Logger.IsVerboseEnabled) Logger.Verbose(Messages.BuildingAndStoringNewInstance); + Logger.LogTrace(Messages.BuildingAndStoringNewInstance); return _instance = _resolve(container); } } diff --git a/src/NEventStore/OptimisticEventStore.cs b/src/NEventStore/OptimisticEventStore.cs index c5e84d0a8..fe702b371 100644 --- a/src/NEventStore/OptimisticEventStore.cs +++ b/src/NEventStore/OptimisticEventStore.cs @@ -3,12 +3,13 @@ namespace NEventStore using System; using System.Collections.Generic; using System.Linq; + using Microsoft.Extensions.Logging; using NEventStore.Logging; using NEventStore.Persistence; public class OptimisticEventStore : IStoreEvents, ICommitEvents { - private static readonly ILog Logger = LogFactory.BuildLogger(typeof(OptimisticEventStore)); + private static readonly ILogger Logger = LogFactory.BuildLogger(typeof(OptimisticEventStore)); private readonly IPersistStreams _persistence; private readonly IEnumerable _pipelineHooks; @@ -42,22 +43,22 @@ public virtual ICommit Commit(CommitAttempt attempt) Guard.NotNull(() => attempt, attempt); foreach (var hook in _pipelineHooks) { - if (Logger.IsVerboseEnabled) Logger.Verbose(Resources.InvokingPreCommitHooks, attempt.CommitId, hook.GetType()); + Logger.LogTrace(Resources.InvokingPreCommitHooks, attempt.CommitId, hook.GetType()); if (hook.PreCommit(attempt)) { continue; } - if (Logger.IsInfoEnabled) Logger.Info(Resources.CommitRejectedByPipelineHook, hook.GetType(), attempt.CommitId); + Logger.LogInformation(Resources.CommitRejectedByPipelineHook, hook.GetType(), attempt.CommitId); return null; } - if (Logger.IsVerboseEnabled) Logger.Verbose(Resources.CommittingAttempt, attempt.CommitId, attempt.Events?.Count ?? 0); + Logger.LogTrace(Resources.CommittingAttempt, attempt.CommitId, attempt.Events?.Count ?? 0); ICommit commit = _persistence.Commit(attempt); foreach (var hook in _pipelineHooks) { - if (Logger.IsVerboseEnabled) Logger.Verbose(Resources.InvokingPostCommitPipelineHooks, attempt.CommitId, hook.GetType()); + Logger.LogTrace(Resources.InvokingPostCommitPipelineHooks, attempt.CommitId, hook.GetType()); hook.PostCommit(commit); } return commit; @@ -71,7 +72,7 @@ public void Dispose() public virtual IEventStream CreateStream(string bucketId, string streamId) { - if (Logger.IsDebugEnabled) Logger.Debug(Resources.CreatingStream, streamId, bucketId); + Logger.LogDebug(Resources.CreatingStream, streamId, bucketId); return new OptimisticEventStream(bucketId, streamId, this); } @@ -79,7 +80,7 @@ public virtual IEventStream OpenStream(string bucketId, string streamId, int min { maxRevision = maxRevision <= 0 ? int.MaxValue : maxRevision; - if (Logger.IsVerboseEnabled) Logger.Verbose(Resources.OpeningStreamAtRevision, streamId, bucketId, minRevision, maxRevision); + Logger.LogTrace(Resources.OpeningStreamAtRevision, streamId, bucketId, minRevision, maxRevision); return new OptimisticEventStream(bucketId, streamId, this, minRevision, maxRevision); } @@ -90,7 +91,7 @@ public virtual IEventStream OpenStream(ISnapshot snapshot, int maxRevision) throw new ArgumentNullException(nameof(snapshot)); } - if (Logger.IsVerboseEnabled) Logger.Verbose(Resources.OpeningStreamWithSnapshot, snapshot.StreamId, snapshot.StreamRevision, maxRevision); + Logger.LogTrace(Resources.OpeningStreamWithSnapshot, snapshot.StreamId, snapshot.StreamRevision, maxRevision); maxRevision = maxRevision <= 0 ? int.MaxValue : maxRevision; return new OptimisticEventStream(snapshot, this, maxRevision); } @@ -102,7 +103,7 @@ protected virtual void Dispose(bool disposing) return; } - if (Logger.IsInfoEnabled) Logger.Info(Resources.ShuttingDownStore); + Logger.LogInformation(Resources.ShuttingDownStore); _persistence.Dispose(); foreach (var hook in _pipelineHooks) { diff --git a/src/NEventStore/OptimisticEventStream.cs b/src/NEventStore/OptimisticEventStream.cs index 8511b76a1..4fe2450e2 100644 --- a/src/NEventStore/OptimisticEventStream.cs +++ b/src/NEventStore/OptimisticEventStream.cs @@ -4,13 +4,14 @@ namespace NEventStore using System.Collections.Generic; using System.Diagnostics.CodeAnalysis; using System.Linq; + using Microsoft.Extensions.Logging; using NEventStore.Logging; [SuppressMessage("Microsoft.Naming", "CA1711:IdentifiersShouldNotHaveIncorrectSuffix", Justification = "This behaves like a stream--not a .NET 'Stream' object, but a stream nonetheless.")] public sealed class OptimisticEventStream : IEventStream { - private static readonly ILog Logger = LogFactory.BuildLogger(typeof(OptimisticEventStream)); + private static readonly ILogger Logger = LogFactory.BuildLogger(typeof(OptimisticEventStream)); private readonly ICollection _committed = new LinkedList(); private readonly ImmutableCollection _committedImmutableWrapper; private readonly IDictionary _committedHeaders = new Dictionary(); @@ -74,17 +75,17 @@ public void Add(EventMessage uncommittedEvent) throw new ArgumentNullException(nameof(uncommittedEvent.Body)); } - if (Logger.IsVerboseEnabled) Logger.Verbose(Resources.AppendingUncommittedToStream, uncommittedEvent.Body.GetType(), StreamId); + Logger.LogTrace(Resources.AppendingUncommittedToStream, uncommittedEvent.Body.GetType(), StreamId); _events.Add(uncommittedEvent); } public void CommitChanges(Guid commitId) { - if (Logger.IsVerboseEnabled) Logger.Verbose(Resources.AttemptingToCommitChanges, StreamId); + Logger.LogTrace(Resources.AttemptingToCommitChanges, StreamId); if (_isPartialStream) { - if (Logger.IsDebugEnabled) Logger.Debug(Resources.CannotAddCommitsToPartiallyLoadedStream, StreamId, StreamRevision); + Logger.LogDebug(Resources.CannotAddCommitsToPartiallyLoadedStream, StreamId, StreamRevision); RefreshStreamAfterConcurrencyException(); @@ -107,7 +108,7 @@ public void CommitChanges(Guid commitId) } catch (ConcurrencyException cex) { - if (Logger.IsDebugEnabled) Logger.Debug(Resources.UnderlyingStreamHasChanged, StreamId, cex.Message); + Logger.LogDebug(Resources.UnderlyingStreamHasChanged, StreamId, cex.Message); RefreshStreamAfterConcurrencyException(); @@ -124,7 +125,7 @@ private void RefreshStreamAfterConcurrencyException() public void ClearChanges() { - if (Logger.IsVerboseEnabled) Logger.Verbose(Resources.ClearingUncommittedChanges, StreamId); + Logger.LogTrace(Resources.ClearingUncommittedChanges, StreamId); _events.Clear(); UncommittedHeaders.Clear(); } @@ -141,11 +142,11 @@ private void PopulateStream(int minRevision, int maxRevision, IEnumerable maxRevision) { _isPartialStream = true; - if (Logger.IsDebugEnabled) Logger.Debug(Resources.IgnoringBeyondRevision, commit.CommitId, StreamId, maxRevision); + Logger.LogDebug(Resources.IgnoringBeyondRevision, commit.CommitId, StreamId, maxRevision); return; } - if (Logger.IsVerboseEnabled) Logger.Verbose(Resources.AddingCommitsToStream, commit.CommitId, commit.Events.Count, StreamId); + Logger.LogTrace(Resources.AddingCommitsToStream, commit.CommitId, commit.Events.Count, StreamId); CommitSequence = commit.CommitSequence; @@ -169,13 +170,13 @@ private void CopyToEvents(int minRevision, int maxRevision, int currentRevision, if (currentRevision > maxRevision) { _isPartialStream = true; - if (Logger.IsDebugEnabled) Logger.Debug(Resources.IgnoringBeyondRevision, commit.CommitId, StreamId, maxRevision); + Logger.LogDebug(Resources.IgnoringBeyondRevision, commit.CommitId, StreamId, maxRevision); break; } if (currentRevision++ < minRevision) { - if (Logger.IsDebugEnabled) Logger.Debug(Resources.IgnoringBeforeRevision, commit.CommitId, StreamId, maxRevision); + Logger.LogDebug(Resources.IgnoringBeforeRevision, commit.CommitId, StreamId, maxRevision); continue; } @@ -196,7 +197,7 @@ private bool HasChanges() return true; } - if (Logger.IsInfoEnabled) Logger.Info(Resources.NoChangesToCommit, StreamId); + Logger.LogInformation(Resources.NoChangesToCommit, StreamId); return false; } @@ -204,7 +205,7 @@ private void PersistChanges(Guid commitId) { CommitAttempt attempt = BuildCommitAttempt(commitId); - if (Logger.IsDebugEnabled) Logger.Debug(Resources.PersistingCommit, commitId, StreamId, attempt.Events?.Count ?? 0); + Logger.LogDebug(Resources.PersistingCommit, commitId, StreamId, attempt.Events?.Count ?? 0); ICommit commit = _persistence.Commit(attempt); PopulateStream(StreamRevision + 1, attempt.StreamRevision, new[] { commit }); @@ -213,7 +214,7 @@ private void PersistChanges(Guid commitId) private CommitAttempt BuildCommitAttempt(Guid commitId) { - if (Logger.IsVerboseEnabled) Logger.Verbose(Resources.BuildingCommitAttempt, commitId, StreamId); + Logger.LogTrace(Resources.BuildingCommitAttempt, commitId, StreamId); return new CommitAttempt( BucketId, StreamId, diff --git a/src/NEventStore/OptimisticPipelineHook.cs b/src/NEventStore/OptimisticPipelineHook.cs index c4d1f8210..371c0d257 100644 --- a/src/NEventStore/OptimisticPipelineHook.cs +++ b/src/NEventStore/OptimisticPipelineHook.cs @@ -3,6 +3,7 @@ namespace NEventStore using System; using System.Collections.Generic; using System.Linq; + using Microsoft.Extensions.Logging; using NEventStore.Logging; using NEventStore.Persistence; @@ -12,7 +13,7 @@ namespace NEventStore public class OptimisticPipelineHook : PipelineHookBase { internal const int MaxStreamsToTrack = 100; - private static readonly ILog Logger = LogFactory.BuildLogger(typeof(OptimisticPipelineHook)); + private static readonly ILogger Logger = LogFactory.BuildLogger(typeof(OptimisticPipelineHook)); private readonly Dictionary _heads = new Dictionary(); //TODO use concurrent collections private readonly LinkedList _maxItemsToTrack = new LinkedList(); private readonly int _maxStreamsToTrack; @@ -23,7 +24,7 @@ public OptimisticPipelineHook() public OptimisticPipelineHook(int maxStreamsToTrack) { - if (Logger.IsDebugEnabled) Logger.Debug(Resources.TrackingStreams, maxStreamsToTrack); + Logger.LogDebug(Resources.TrackingStreams, maxStreamsToTrack); _maxStreamsToTrack = maxStreamsToTrack; } @@ -35,7 +36,7 @@ public override ICommit Select(ICommit committed) public override bool PreCommit(CommitAttempt attempt) { - if (Logger.IsVerboseEnabled) Logger.Verbose(Resources.OptimisticConcurrencyCheck, attempt.StreamId); + Logger.LogTrace(Resources.OptimisticConcurrencyCheck, attempt.StreamId); ICommit head = GetStreamHead(GetHeadKey(attempt)); if (head == null) @@ -91,7 +92,7 @@ public override bool PreCommit(CommitAttempt attempt) )); // beyond the end of the stream } - if (Logger.IsVerboseEnabled) Logger.Verbose(Resources.NoConflicts, attempt.StreamId); + Logger.LogTrace(Resources.NoConflicts, attempt.StreamId); return true; } @@ -179,7 +180,7 @@ private static bool AlreadyTracked(ICommit head) private void TrackUpToCapacity(ICommit committed) { - if (Logger.IsVerboseEnabled) Logger.Verbose(Resources.TrackingCommit, committed.CommitSequence, committed.StreamId); + Logger.LogTrace(Resources.TrackingCommit, committed.CommitSequence, committed.StreamId); _maxItemsToTrack.AddFirst(GetHeadKey(committed)); if (_maxItemsToTrack.Count <= _maxStreamsToTrack) { @@ -187,7 +188,7 @@ private void TrackUpToCapacity(ICommit committed) } HeadKey expired = _maxItemsToTrack.Last.Value; - if (Logger.IsVerboseEnabled) Logger.Verbose(Resources.NoLongerTrackingStream, expired); + Logger.LogTrace(Resources.NoLongerTrackingStream, expired); _heads.Remove(expired); _maxItemsToTrack.RemoveLast(); diff --git a/src/NEventStore/Persistence/InMemory/InMemoryPersistenceEngine.cs b/src/NEventStore/Persistence/InMemory/InMemoryPersistenceEngine.cs index ba7163554..524fb40e1 100644 --- a/src/NEventStore/Persistence/InMemory/InMemoryPersistenceEngine.cs +++ b/src/NEventStore/Persistence/InMemory/InMemoryPersistenceEngine.cs @@ -5,11 +5,12 @@ namespace NEventStore.Persistence.InMemory using System.Collections.Generic; using System.Linq; using System.Threading; + using Microsoft.Extensions.Logging; using NEventStore.Logging; public class InMemoryPersistenceEngine : IPersistStreams { - private static readonly ILog Logger = LogFactory.BuildLogger(typeof(InMemoryPersistenceEngine)); + private static readonly ILogger Logger = LogFactory.BuildLogger(typeof(InMemoryPersistenceEngine)); private readonly ConcurrentDictionary _buckets = new ConcurrentDictionary(); private bool _disposed; private int _checkpoint; @@ -27,41 +28,41 @@ public void Dispose() public void Initialize() { - if (Logger.IsInfoEnabled) Logger.Info(Resources.InitializingEngine); + Logger.LogInformation(Resources.InitializingEngine); } public IEnumerable GetFrom(string bucketId, string streamId, int minRevision, int maxRevision) { ThrowWhenDisposed(); - if (Logger.IsDebugEnabled) Logger.Debug(Resources.GettingAllCommitsFromRevision, streamId, minRevision, maxRevision); + Logger.LogDebug(Resources.GettingAllCommitsFromRevision, streamId, minRevision, maxRevision); return this[bucketId].GetFrom(streamId, minRevision, maxRevision); } public IEnumerable GetFrom(string bucketId, DateTime start) { ThrowWhenDisposed(); - if (Logger.IsDebugEnabled) Logger.Debug(Resources.GettingAllCommitsFromTime, bucketId, start); + Logger.LogDebug(Resources.GettingAllCommitsFromTime, bucketId, start); return this[bucketId].GetFrom(start); } public IEnumerable GetFrom(string bucketId, Int64 checkpointToken) { ThrowWhenDisposed(); - if (Logger.IsDebugEnabled) Logger.Debug(Resources.GettingAllCommitsFromBucketAndCheckpoint, bucketId, checkpointToken); + Logger.LogDebug(Resources.GettingAllCommitsFromBucketAndCheckpoint, bucketId, checkpointToken); return this[bucketId].GetFrom(checkpointToken); } public IEnumerable GetFromTo(string bucketId, Int64 from, Int64 to) { ThrowWhenDisposed(); - if (Logger.IsDebugEnabled) Logger.Debug(Resources.GettingCommitsFromBucketAndFromToCheckpoint, bucketId, from, to); + Logger.LogDebug(Resources.GettingCommitsFromBucketAndFromToCheckpoint, bucketId, from, to); return this[bucketId].GetFromTo(from, to); } public IEnumerable GetFrom(Int64 checkpointToken) { ThrowWhenDisposed(); - if (Logger.IsDebugEnabled) Logger.Debug(Resources.GettingAllCommitsFromCheckpoint, checkpointToken); + Logger.LogDebug(Resources.GettingAllCommitsFromCheckpoint, checkpointToken); return _buckets .Values .SelectMany(b => b.GetCommits()) @@ -73,7 +74,7 @@ public IEnumerable GetFrom(Int64 checkpointToken) public IEnumerable GetFromTo(Int64 from, Int64 to) { ThrowWhenDisposed(); - if (Logger.IsDebugEnabled) Logger.Debug(Resources.GettingCommitsFromToCheckpoint, from, to); + Logger.LogDebug(Resources.GettingCommitsFromToCheckpoint, from, to); return _buckets .Values .SelectMany(b => b.GetCommits()) @@ -85,42 +86,42 @@ public IEnumerable GetFromTo(Int64 from, Int64 to) public IEnumerable GetFromTo(string bucketId, DateTime start, DateTime end) { ThrowWhenDisposed(); - if (Logger.IsDebugEnabled) Logger.Debug(Resources.GettingAllCommitsFromToTime, start, end); + Logger.LogDebug(Resources.GettingAllCommitsFromToTime, start, end); return this[bucketId].GetFromTo(start, end); } public ICommit Commit(CommitAttempt attempt) { ThrowWhenDisposed(); - if (Logger.IsDebugEnabled) Logger.Debug(Resources.AttemptingToCommit, attempt.CommitId, attempt.StreamId, attempt.CommitSequence); + Logger.LogDebug(Resources.AttemptingToCommit, attempt.CommitId, attempt.StreamId, attempt.CommitSequence); return this[attempt.BucketId].Commit(attempt, Interlocked.Increment(ref _checkpoint)); } public IEnumerable GetStreamsToSnapshot(string bucketId, int maxThreshold) { ThrowWhenDisposed(); - if (Logger.IsDebugEnabled) Logger.Debug(Resources.GettingStreamsToSnapshot, bucketId, maxThreshold); + Logger.LogDebug(Resources.GettingStreamsToSnapshot, bucketId, maxThreshold); return this[bucketId].GetStreamsToSnapshot(maxThreshold); } public ISnapshot GetSnapshot(string bucketId, string streamId, int maxRevision) { ThrowWhenDisposed(); - if (Logger.IsDebugEnabled) Logger.Debug(Resources.GettingSnapshotForStream, bucketId, streamId, maxRevision); + Logger.LogDebug(Resources.GettingSnapshotForStream, bucketId, streamId, maxRevision); return this[bucketId].GetSnapshot(streamId, maxRevision); } public bool AddSnapshot(ISnapshot snapshot) { ThrowWhenDisposed(); - if (Logger.IsDebugEnabled) Logger.Debug(Resources.AddingSnapshot, snapshot.StreamId, snapshot.StreamRevision); + Logger.LogDebug(Resources.AddingSnapshot, snapshot.StreamId, snapshot.StreamRevision); return this[snapshot.BucketId].AddSnapshot(snapshot); } public void Purge() { ThrowWhenDisposed(); - if (Logger.IsWarnEnabled) Logger.Warn(Resources.PurgingStore); + Logger.LogWarning(Resources.PurgingStore); foreach (var bucket in _buckets.Values) { bucket.Purge(); @@ -140,7 +141,7 @@ public void Drop() public void DeleteStream(string bucketId, string streamId) { - if (Logger.IsWarnEnabled) Logger.Warn(Resources.DeletingStream, streamId, bucketId); + Logger.LogWarning(Resources.DeletingStream, streamId, bucketId); if (!_buckets.TryGetValue(bucketId, out Bucket bucket)) { return; @@ -160,7 +161,7 @@ private void Dispose(bool disposing) #pragma warning restore RCS1163 // Unused parameter. { _disposed = true; - if (Logger.IsInfoEnabled) Logger.Info(Resources.DisposingEngine); + Logger.LogInformation(Resources.DisposingEngine); } private void ThrowWhenDisposed() @@ -170,7 +171,7 @@ private void ThrowWhenDisposed() return; } - if (Logger.IsWarnEnabled) Logger.Warn(Resources.AlreadyDisposed); + Logger.LogWarning(Resources.AlreadyDisposed); throw new ObjectDisposedException(Resources.AlreadyDisposed); } @@ -400,7 +401,7 @@ public ICommit Commit(CommitAttempt attempt, Int64 checkpoint) _potentialConflicts.Add(new IdentityForConcurrencyConflictDetection(commit)); IStreamHead head = _heads.FirstOrDefault(x => x.StreamId == commit.StreamId); _heads.Remove(head); - if (Logger.IsDebugEnabled) Logger.Debug(Resources.UpdatingStreamHead, commit.StreamId); + Logger.LogDebug(Resources.UpdatingStreamHead, commit.StreamId); int snapshotRevision = head?.SnapshotRevision ?? 0; _heads.Add(new StreamHead(commit.BucketId, commit.StreamId, commit.StreamRevision, snapshotRevision)); return commit; diff --git a/src/NEventStore/Persistence/PipelineHooksAwarePersistanceDecorator.cs b/src/NEventStore/Persistence/PipelineHooksAwarePersistanceDecorator.cs index c69139770..b76657a1e 100644 --- a/src/NEventStore/Persistence/PipelineHooksAwarePersistanceDecorator.cs +++ b/src/NEventStore/Persistence/PipelineHooksAwarePersistanceDecorator.cs @@ -3,11 +3,12 @@ namespace NEventStore.Persistence using System; using System.Collections.Generic; using System.Linq; + using Microsoft.Extensions.Logging; using NEventStore.Logging; public sealed class PipelineHooksAwarePersistanceDecorator : IPersistStreams { - private static readonly ILog Logger = LogFactory.BuildLogger(typeof(PipelineHooksAwarePersistanceDecorator)); + private static readonly ILogger Logger = LogFactory.BuildLogger(typeof(PipelineHooksAwarePersistanceDecorator)); private readonly IPersistStreams _original; private readonly IEnumerable _pipelineHooks; @@ -126,13 +127,13 @@ private IEnumerable ExecuteHooks(IEnumerable commits) ICommit filtered = commit; foreach (var hook in _pipelineHooks.Where(x => (filtered = x.Select(filtered)) == null)) { - if (Logger.IsInfoEnabled) Logger.Info(Resources.PipelineHookSkippedCommit, hook.GetType(), commit.CommitId); + Logger.LogInformation(Resources.PipelineHookSkippedCommit, hook.GetType(), commit.CommitId); break; } if (filtered == null) { - if (Logger.IsInfoEnabled) Logger.Info(Resources.PipelineHookFilteredCommit); + Logger.LogInformation(Resources.PipelineHookFilteredCommit); } else { diff --git a/src/NEventStore/PersistenceWireup.cs b/src/NEventStore/PersistenceWireup.cs index 374d1c8d1..b12c4b350 100644 --- a/src/NEventStore/PersistenceWireup.cs +++ b/src/NEventStore/PersistenceWireup.cs @@ -1,6 +1,7 @@ namespace NEventStore { using System; + using Microsoft.Extensions.Logging; using NEventStore.Diagnostics; using NEventStore.Logging; using NEventStore.Persistence; @@ -8,7 +9,7 @@ namespace NEventStore public class PersistenceWireup : Wireup { - private static readonly ILog Logger = LogFactory.BuildLogger(typeof(PersistenceWireup)); + private static readonly ILogger Logger = LogFactory.BuildLogger(typeof(PersistenceWireup)); private bool _initialize; #if !NETSTANDARD1_6 && !NETSTANDARD2_0 private bool _tracking; @@ -29,7 +30,7 @@ public PersistenceWireup(Wireup inner) public virtual PersistenceWireup WithPersistence(IPersistStreams instance) { - if (Logger.IsInfoEnabled) Logger.Info(Messages.RegisteringPersistenceEngine, instance.GetType()); + Logger.LogInformation(Messages.RegisteringPersistenceEngine, instance.GetType()); With(instance); return this; } @@ -41,7 +42,7 @@ protected virtual SerializationWireup WithSerializer(ISerialize serializer) public virtual PersistenceWireup InitializeStorageEngine() { - if (Logger.IsInfoEnabled) Logger.Info(Messages.ConfiguringEngineInitialization); + Logger.LogInformation(Messages.ConfiguringEngineInitialization); _initialize = true; return this; } @@ -54,7 +55,7 @@ public virtual PersistenceWireup TrackPerformanceInstance(string instanceName) throw new ArgumentNullException(nameof(instanceName), Messages.InstanceCannotBeNull); } - if (Logger.IsInfoEnabled) Logger.Info(Messages.ConfiguringEnginePerformanceTracking); + Logger.LogInformation(Messages.ConfiguringEnginePerformanceTracking); _tracking = true; _trackingInstanceName = instanceName; return this; @@ -91,13 +92,13 @@ public virtual PersistenceWireup EnlistInAmbientTransaction() public override IStoreEvents Build() #pragma warning restore S125 // Sections of code should not be commented out { - if (Logger.IsInfoEnabled) Logger.Info(Messages.BuildingEngine); + Logger.LogInformation(Messages.BuildingEngine); var engine = Container.Resolve(); if (_initialize) { - if (Logger.IsDebugEnabled) Logger.Debug(Messages.InitializingEngine); + Logger.LogDebug(Messages.InitializingEngine); engine.Initialize(); } diff --git a/src/NEventStore/PersistenceWireupExtensions.cs b/src/NEventStore/PersistenceWireupExtensions.cs index 28e8a6ecb..7294d7cb0 100644 --- a/src/NEventStore/PersistenceWireupExtensions.cs +++ b/src/NEventStore/PersistenceWireupExtensions.cs @@ -1,16 +1,17 @@ namespace NEventStore { using Logging; + using Microsoft.Extensions.Logging; using NEventStore.Persistence; using NEventStore.Persistence.InMemory; public static class PersistenceWireupExtensions { - private static readonly ILog Logger = LogFactory.BuildLogger(typeof(OptimisticPipelineHook)); + private static readonly ILogger Logger = LogFactory.BuildLogger(typeof(OptimisticPipelineHook)); public static PersistenceWireup UsingInMemoryPersistence(this Wireup wireup) { - if (Logger.IsInfoEnabled) Logger.Info(Resources.WireupSetPersistenceEngine, "InMemoryPersistenceEngine"); + Logger.LogInformation(Resources.WireupSetPersistenceEngine, "InMemoryPersistenceEngine"); wireup.With(new InMemoryPersistenceEngine()); return new PersistenceWireup(wireup); diff --git a/src/NEventStore/Serialization/BinarySerializer.cs b/src/NEventStore/Serialization/BinarySerializer.cs index de7784b3c..ba2b68158 100644 --- a/src/NEventStore/Serialization/BinarySerializer.cs +++ b/src/NEventStore/Serialization/BinarySerializer.cs @@ -4,22 +4,23 @@ namespace NEventStore.Serialization using System.IO; using System.Runtime.Serialization; using System.Runtime.Serialization.Formatters.Binary; + using Microsoft.Extensions.Logging; using NEventStore.Logging; public class BinarySerializer : ISerialize { - private static readonly ILog Logger = LogFactory.BuildLogger(typeof (BinarySerializer)); + private static readonly ILogger Logger = LogFactory.BuildLogger(typeof (BinarySerializer)); private readonly IFormatter _formatter = new BinaryFormatter(); public virtual void Serialize(Stream output, T graph) { - if (Logger.IsVerboseEnabled) Logger.Verbose(Messages.SerializingGraph, typeof (T)); + Logger.LogTrace(Messages.SerializingGraph, typeof (T)); _formatter.Serialize(output, graph); } public virtual T Deserialize(Stream input) { - if (Logger.IsVerboseEnabled) Logger.Verbose(Messages.DeserializingStream, typeof (T)); + Logger.LogTrace(Messages.DeserializingStream, typeof (T)); return (T) _formatter.Deserialize(input); } } diff --git a/src/NEventStore/Serialization/ByteStreamDocumentSerializer.cs b/src/NEventStore/Serialization/ByteStreamDocumentSerializer.cs index bda5445c2..055896a55 100644 --- a/src/NEventStore/Serialization/ByteStreamDocumentSerializer.cs +++ b/src/NEventStore/Serialization/ByteStreamDocumentSerializer.cs @@ -1,11 +1,12 @@ namespace NEventStore.Serialization { using System; + using Microsoft.Extensions.Logging; using NEventStore.Logging; public class ByteStreamDocumentSerializer : IDocumentSerializer { - private static readonly ILog Logger = LogFactory.BuildLogger(typeof (ByteStreamDocumentSerializer)); + private static readonly ILogger Logger = LogFactory.BuildLogger(typeof (ByteStreamDocumentSerializer)); private readonly ISerialize _serializer; public ByteStreamDocumentSerializer(ISerialize serializer) @@ -15,13 +16,13 @@ public ByteStreamDocumentSerializer(ISerialize serializer) public object Serialize(T graph) { - if (Logger.IsVerboseEnabled) Logger.Verbose(Messages.SerializingGraph, typeof (T)); + Logger.LogTrace(Messages.SerializingGraph, typeof (T)); return _serializer.Serialize(graph); } public T Deserialize(object document) { - if (Logger.IsVerboseEnabled) Logger.Verbose(Messages.DeserializingStream, typeof (T)); + Logger.LogTrace(Messages.DeserializingStream, typeof (T)); byte[] bytes = FromBase64(document as string) ?? document as byte[]; return _serializer.Deserialize(bytes); } @@ -33,7 +34,7 @@ private static byte[] FromBase64(string value) return null; } - if (Logger.IsVerboseEnabled) Logger.Verbose(Messages.InspectingTextStream); + Logger.LogTrace(Messages.InspectingTextStream); try { diff --git a/src/NEventStore/Serialization/GzipSerializer.cs b/src/NEventStore/Serialization/GzipSerializer.cs index 5508b0233..1d8400c79 100644 --- a/src/NEventStore/Serialization/GzipSerializer.cs +++ b/src/NEventStore/Serialization/GzipSerializer.cs @@ -2,11 +2,12 @@ namespace NEventStore.Serialization { using System.IO; using System.IO.Compression; + using Microsoft.Extensions.Logging; using NEventStore.Logging; public class GzipSerializer : ISerialize { - private static readonly ILog Logger = LogFactory.BuildLogger(typeof (GzipSerializer)); + private static readonly ILogger Logger = LogFactory.BuildLogger(typeof (GzipSerializer)); private readonly ISerialize _inner; public GzipSerializer(ISerialize inner) @@ -16,14 +17,14 @@ public GzipSerializer(ISerialize inner) public virtual void Serialize(Stream output, T graph) { - if (Logger.IsVerboseEnabled) Logger.Verbose(Messages.SerializingGraph, typeof (T)); + Logger.LogTrace(Messages.SerializingGraph, typeof (T)); using (var compress = new DeflateStream(output, CompressionMode.Compress, true)) _inner.Serialize(compress, graph); } public virtual T Deserialize(Stream input) { - if (Logger.IsVerboseEnabled) Logger.Verbose(Messages.DeserializingStream, typeof (T)); + Logger.LogTrace(Messages.DeserializingStream, typeof (T)); using (var decompress = new DeflateStream(input, CompressionMode.Decompress, true)) return _inner.Deserialize(decompress); } diff --git a/src/NEventStore/Serialization/RijndaelSerializer.cs b/src/NEventStore/Serialization/RijndaelSerializer.cs index 6820a7ba6..8c56f2ca8 100644 --- a/src/NEventStore/Serialization/RijndaelSerializer.cs +++ b/src/NEventStore/Serialization/RijndaelSerializer.cs @@ -4,13 +4,14 @@ namespace NEventStore.Serialization using System.Collections; using System.IO; using System.Security.Cryptography; + using Microsoft.Extensions.Logging; using NEventStore.Logging; #if !NETSTANDARD1_6 public class RijndaelSerializer : ISerialize { private const int KeyLength = 16; // bytes - private static readonly ILog Logger = LogFactory.BuildLogger(typeof (RijndaelSerializer)); + private static readonly ILogger Logger = LogFactory.BuildLogger(typeof (RijndaelSerializer)); private readonly byte[] _encryptionKey; private readonly ISerialize _inner; @@ -27,7 +28,7 @@ public RijndaelSerializer(ISerialize inner, byte[] encryptionKey) public virtual void Serialize(Stream output, T graph) { - if (Logger.IsVerboseEnabled) Logger.Verbose(Messages.SerializingGraph, typeof (T)); + Logger.LogTrace(Messages.SerializingGraph, typeof (T)); using (var rijndael = new RijndaelManaged()) { @@ -49,7 +50,7 @@ public virtual void Serialize(Stream output, T graph) public virtual T Deserialize(Stream input) { - if (Logger.IsVerboseEnabled) Logger.Verbose(Messages.DeserializingStream, typeof (T)); + Logger.LogTrace(Messages.DeserializingStream, typeof (T)); using (var rijndael = new RijndaelManaged()) { diff --git a/src/NEventStore/SerializationWireup.cs b/src/NEventStore/SerializationWireup.cs index 6f145ac65..659041fa4 100644 --- a/src/NEventStore/SerializationWireup.cs +++ b/src/NEventStore/SerializationWireup.cs @@ -1,11 +1,12 @@ namespace NEventStore { + using Microsoft.Extensions.Logging; using NEventStore.Logging; using NEventStore.Serialization; public class SerializationWireup : Wireup { - private static readonly ILog Logger = LogFactory.BuildLogger(typeof (SerializationWireup)); + private static readonly ILogger Logger = LogFactory.BuildLogger(typeof (SerializationWireup)); public SerializationWireup(Wireup inner, ISerialize serializer) : base(inner) @@ -15,10 +16,10 @@ public SerializationWireup(Wireup inner, ISerialize serializer) public SerializationWireup Compress() { - if (Logger.IsDebugEnabled) Logger.Debug(Messages.ConfiguringCompression); + Logger.LogDebug(Messages.ConfiguringCompression); var wrapped = Container.Resolve(); - if (Logger.IsInfoEnabled) Logger.Info(Messages.WrappingSerializerGZip, wrapped.GetType()); + Logger.LogInformation(Messages.WrappingSerializerGZip, wrapped.GetType()); Container.Register(new GzipSerializer(wrapped)); return this; } @@ -26,10 +27,10 @@ public SerializationWireup Compress() #if !NETSTANDARD1_6 public SerializationWireup EncryptWith(byte[] encryptionKey) { - if (Logger.IsDebugEnabled) Logger.Debug(Messages.ConfiguringEncryption); + Logger.LogDebug(Messages.ConfiguringEncryption); var wrapped = Container.Resolve(); - if (Logger.IsInfoEnabled) Logger.Info(Messages.WrappingSerializerEncryption, wrapped.GetType()); + Logger.LogInformation(Messages.WrappingSerializerEncryption, wrapped.GetType()); Container.Register(new RijndaelSerializer(wrapped, encryptionKey)); return this; } diff --git a/src/NEventStore/SerializationWireupExtensions.cs b/src/NEventStore/SerializationWireupExtensions.cs index 4f75cfede..02d46333c 100644 --- a/src/NEventStore/SerializationWireupExtensions.cs +++ b/src/NEventStore/SerializationWireupExtensions.cs @@ -1,23 +1,24 @@ namespace NEventStore { using Logging; + using Microsoft.Extensions.Logging; using NEventStore.Serialization; public static class SerializationWireupExtensions { - private static readonly ILog Logger = LogFactory.BuildLogger(typeof(PersistenceWireup)); + private static readonly ILogger Logger = LogFactory.BuildLogger(typeof(PersistenceWireup)); #if !NETSTANDARD1_6 public static SerializationWireup UsingBinarySerialization(this PersistenceWireup wireup) { - if (Logger.IsInfoEnabled) Logger.Info(Resources.WireupSetSerializer, "Binary"); + Logger.LogInformation(Resources.WireupSetSerializer, "Binary"); return new SerializationWireup(wireup, new BinarySerializer()); } #endif public static SerializationWireup UsingCustomSerialization(this PersistenceWireup wireup, ISerialize serializer) { - if (Logger.IsInfoEnabled) Logger.Info(Resources.WireupSetSerializer, "Custom" + serializer.GetType()); + Logger.LogInformation(Resources.WireupSetSerializer, "Custom" + serializer.GetType()); return new SerializationWireup(wireup, serializer); } } diff --git a/src/NEventStore/Wireup.cs b/src/NEventStore/Wireup.cs index 2421a2097..42ec37292 100644 --- a/src/NEventStore/Wireup.cs +++ b/src/NEventStore/Wireup.cs @@ -6,12 +6,13 @@ namespace NEventStore using NEventStore.Persistence; using NEventStore.Persistence.InMemory; using Logging; + using Microsoft.Extensions.Logging; public class Wireup { private readonly NanoContainer _container; private readonly Wireup _inner; - private readonly ILog Logger = LogFactory.BuildLogger(typeof(Wireup)); + private readonly ILogger Logger = LogFactory.BuildLogger(typeof(Wireup)); protected Wireup(NanoContainer container) { @@ -51,7 +52,7 @@ public virtual Wireup HookIntoPipelineUsing(IEnumerable hooks) public virtual Wireup HookIntoPipelineUsing(params IPipelineHook[] hooks) { - if (Logger.IsInfoEnabled) Logger.Info(Resources.WireupHookIntoPipeline, string.Join(", ", hooks.Select(h => h.GetType()))); + Logger.LogInformation(Resources.WireupHookIntoPipeline, string.Join(", ", hooks.Select(h => h.GetType()))); ICollection collection = (hooks ?? new IPipelineHook[] { }).Where(x => x != null).ToArray(); Container.Register(collection); return this;