From 2a8ecfb80756b999dc11edf50b4207bdb2baa176 Mon Sep 17 00:00:00 2001 From: Damian Hickey Date: Sun, 6 Jan 2019 15:20:33 +0100 Subject: [PATCH] Update .pp files --- src/LibLog/LogExtensions.cs.pp | 11 +++++------ src/LibLog/LogProvider.cs.pp | 14 +++++++++++--- src/LibLog/LogProviders/DisposableAction.cs.pp | 2 +- src/LibLog/LogProviders/Log4NetLogProvider.cs.pp | 2 +- src/LibLog/LogProviders/LogMessageFormatter.cs.pp | 4 +++- src/LibLog/LogProviders/LogProviderBase.cs.pp | 2 +- src/LibLog/LogProviders/NLogLogProvider.cs.pp | 11 +++++++++-- src/LibLog/LoggerExecutionWrapper.cs.pp | 10 ++++------ 8 files changed, 35 insertions(+), 21 deletions(-) diff --git a/src/LibLog/LogExtensions.cs.pp b/src/LibLog/LogExtensions.cs.pp index 2ff8130..0670001 100644 --- a/src/LibLog/LogExtensions.cs.pp +++ b/src/LibLog/LogExtensions.cs.pp @@ -508,7 +508,7 @@ // ReSharper disable once UnusedParameter.Local private static void GuardAgainstNullLogger(ILog logger) { - if (logger == null) throw new ArgumentNullException(nameof(logger)); + if (logger == null) throw new ArgumentNullException("logger"); } private static void LogFormat(this ILog logger, LogLevel logLevel, string message, params object[] args) @@ -530,8 +530,7 @@ // Allow passing callsite-logger-type to LogProviderBase using messageFunc internal static Func WrapLogSafeInternal(LoggerExecutionWrapper logger, Func messageFunc) { - string WrappedMessageFunc() - { + var WrappedMessageFunc = new Func(() => { try { return messageFunc(); @@ -543,7 +542,7 @@ } return null; - } + }); return WrappedMessageFunc; } @@ -551,10 +550,10 @@ // Allow passing callsite-logger-type to LogProviderBase using messageFunc private static Func WrapLogInternal(Func messageFunc) { - string WrappedMessageFunc() + var WrappedMessageFunc = new Func(() => { return messageFunc(); - } + }); return WrappedMessageFunc; } diff --git a/src/LibLog/LogProvider.cs.pp b/src/LibLog/LogProvider.cs.pp index ca9f4c3..b9f20a8 100644 --- a/src/LibLog/LogProvider.cs.pp +++ b/src/LibLog/LogProvider.cs.pp @@ -114,7 +114,10 @@ } } - internal static ILogProvider CurrentLogProvider => s_currentLogProvider; + internal static ILogProvider CurrentLogProvider + { + get { return s_currentLogProvider; } + } /// /// Gets a logger for the specified type. @@ -126,7 +129,10 @@ #else internal #endif - static ILog For() => GetLogger(typeof(T)); + static ILog For() + { + return GetLogger(typeof(T)); + } /// /// Gets a logger for the current class. @@ -298,7 +304,9 @@ internal static readonly NoOpLogger Instance = new NoOpLogger(); public bool Log(LogLevel logLevel, Func messageFunc, Exception exception, params object[] formatParameters) - => false; + { + return false; + } } #endif } diff --git a/src/LibLog/LogProviders/DisposableAction.cs.pp b/src/LibLog/LogProviders/DisposableAction.cs.pp index f22fea8..a0243e1 100644 --- a/src/LibLog/LogProviders/DisposableAction.cs.pp +++ b/src/LibLog/LogProviders/DisposableAction.cs.pp @@ -18,7 +18,7 @@ public void Dispose() { - _onDispose?.Invoke(); + if(_onDispose != null) _onDispose.Invoke(); } } } diff --git a/src/LibLog/LogProviders/Log4NetLogProvider.cs.pp b/src/LibLog/LogProviders/Log4NetLogProvider.cs.pp index fe94905..ba4da81 100644 --- a/src/LibLog/LogProviders/Log4NetLogProvider.cs.pp +++ b/src/LibLog/LogProviders/Log4NetLogProvider.cs.pp @@ -372,7 +372,7 @@ case LogLevel.Fatal: return s_levelFatal; default: - throw new ArgumentOutOfRangeException(nameof(logLevel), logLevel, null); + throw new ArgumentOutOfRangeException("logLevel", logLevel, null); } } } diff --git a/src/LibLog/LogProviders/LogMessageFormatter.cs.pp b/src/LibLog/LogProviders/LogMessageFormatter.cs.pp index 390c75c..aec42c9 100644 --- a/src/LibLog/LogProviders/LogMessageFormatter.cs.pp +++ b/src/LibLog/LogProviders/LogMessageFormatter.cs.pp @@ -35,6 +35,7 @@ return () => { var targetMessage = messageBuilder(); + IEnumerable _; return FormatStructuredMessage(targetMessage, formatParameters, out _); }; } @@ -61,7 +62,8 @@ { var arg = match.Groups["arg"].Value; - if (!int.TryParse(arg, out _)) + int result; + if (!int.TryParse(arg, out result)) { processedArguments = processedArguments ?? new List(formatParameters.Length); var argumentIndex = processedArguments.IndexOf(arg); diff --git a/src/LibLog/LogProviders/LogProviderBase.cs.pp b/src/LibLog/LogProviders/LogProviderBase.cs.pp index 3e5de5d..6ad22fd 100644 --- a/src/LibLog/LogProviders/LogProviderBase.cs.pp +++ b/src/LibLog/LogProviders/LogProviderBase.cs.pp @@ -74,7 +74,7 @@ /// A provider-specific method to open a nested diagnostics context. protected virtual OpenNdc GetOpenNdcMethod() { - return _ => NoopDisposableInstance; + return (_) => NoopDisposableInstance; } /// diff --git a/src/LibLog/LogProviders/NLogLogProvider.cs.pp b/src/LibLog/LogProviders/NLogLogProvider.cs.pp index a69d2b4..feb7401 100644 --- a/src/LibLog/LogProviders/NLogLogProvider.cs.pp +++ b/src/LibLog/LogProviders/NLogLogProvider.cs.pp @@ -2,7 +2,8 @@ namespace $rootnamespace$.Logging.LogProviders { using System; - using System.Diagnostics.CodeAnalysis; + using System.Collections.Generic; + using System.Diagnostics.CodeAnalysis; using System.Linq; using System.Linq.Expressions; @@ -21,7 +22,12 @@ _getLoggerByNameDelegate = GetGetLoggerMethodCall(); } - public static bool ProviderIsAvailableOverride { get; set; } = true; + static NLogLogProvider() + { + ProviderIsAvailableOverride = true; + } + + public static bool ProviderIsAvailableOverride { get; set; } public override Logger GetLogger(string name) { @@ -284,6 +290,7 @@ var formatMessage = messageFunc(); if (!s_structuredLoggingEnabled) { + IEnumerable _; formatMessage = LogMessageFormatter.FormatStructuredMessage(formatMessage, formatParameters, diff --git a/src/LibLog/LoggerExecutionWrapper.cs.pp b/src/LibLog/LoggerExecutionWrapper.cs.pp index 2aea0fa..6616513 100644 --- a/src/LibLog/LoggerExecutionWrapper.cs.pp +++ b/src/LibLog/LoggerExecutionWrapper.cs.pp @@ -50,7 +50,7 @@ formatParameters); } - string WrappedMessageFunc() + var WrappedMessageFunc = new Func(() => { try { @@ -62,7 +62,7 @@ } return null; - } + }); // Callsite HACK - Need to ensure proper callsite stack without inlining, so calling the logger within a virtual interface method return _callsiteLogger.Log(WrappedLogger, logLevel, WrappedMessageFunc, exception, formatParameters); @@ -70,14 +70,12 @@ private interface ICallSiteExtension { - bool Log(Logger logger, LogLevel logLevel, Func messageFunc, Exception exception, - object[] formatParameters); + bool Log(Logger logger, LogLevel logLevel, Func messageFunc, Exception exception, object[] formatParameters); } private class CallSiteExtension : ICallSiteExtension { - bool ICallSiteExtension.Log(Logger logger, LogLevel logLevel, Func messageFunc, Exception exception, - object[] formatParameters) + bool ICallSiteExtension.Log(Logger logger, LogLevel logLevel, Func messageFunc, Exception exception, object[] formatParameters) { return logger(logLevel, messageFunc, exception, formatParameters); }