Skip to content
This repository has been archived by the owner on Dec 5, 2019. It is now read-only.

Commit

Permalink
update CS files to C# lang specs prior to v7 (#199)
Browse files Browse the repository at this point in the history
This PR updates all C# spec to the specs prior to C# 7
  • Loading branch information
ericnewton76 authored and damianh committed Jan 6, 2019
1 parent bc09b13 commit 3549f2b
Show file tree
Hide file tree
Showing 8 changed files with 37 additions and 23 deletions.
11 changes: 5 additions & 6 deletions src/LibLog/LogExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -507,7 +507,7 @@ public static void WarnException(this ILog logger, string message, Exception exc
// 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)
Expand All @@ -529,8 +529,7 @@ private static T Return<T>(this T value)
// Allow passing callsite-logger-type to LogProviderBase using messageFunc
internal static Func<string> WrapLogSafeInternal(LoggerExecutionWrapper logger, Func<string> messageFunc)
{
string WrappedMessageFunc()
{
var WrappedMessageFunc = new Func<string>(() => {
try
{
return messageFunc();
Expand All @@ -542,18 +541,18 @@ string WrappedMessageFunc()
}

return null;
}
});

return WrappedMessageFunc;
}

// Allow passing callsite-logger-type to LogProviderBase using messageFunc
private static Func<string> WrapLogInternal(Func<string> messageFunc)
{
string WrappedMessageFunc()
var WrappedMessageFunc = new Func<string>(() =>
{
return messageFunc();
}
});

return WrappedMessageFunc;
}
Expand Down
14 changes: 11 additions & 3 deletions src/LibLog/LogProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,10 @@ internal static Action<ILogProvider> OnCurrentLogProviderSet
}
}

internal static ILogProvider CurrentLogProvider => s_currentLogProvider;
internal static ILogProvider CurrentLogProvider
{
get { return s_currentLogProvider; }
}

/// <summary>
/// Gets a logger for the specified type.
Expand All @@ -125,7 +128,10 @@ internal static Action<ILogProvider> OnCurrentLogProviderSet
#else
internal
#endif
static ILog For<T>() => GetLogger(typeof(T));
static ILog For<T>()
{
return GetLogger(typeof(T));
}

/// <summary>
/// Gets a logger for the current class.
Expand Down Expand Up @@ -297,7 +303,9 @@ internal class NoOpLogger : ILog
internal static readonly NoOpLogger Instance = new NoOpLogger();

public bool Log(LogLevel logLevel, Func<string> messageFunc, Exception exception, params object[] formatParameters)
=> false;
{
return false;
}
}
#endif
}
Expand Down
2 changes: 1 addition & 1 deletion src/LibLog/LogProviders/DisposableAction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public DisposableAction(Action onDispose = null)

public void Dispose()
{
_onDispose?.Invoke();
if(_onDispose != null) _onDispose.Invoke();
}
}
}
2 changes: 1 addition & 1 deletion src/LibLog/LogProviders/Log4NetLogProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,7 @@ private object TranslateLevel(LogLevel logLevel)
case LogLevel.Fatal:
return s_levelFatal;
default:
throw new ArgumentOutOfRangeException(nameof(logLevel), logLevel, null);
throw new ArgumentOutOfRangeException("logLevel", logLevel, null);
}
}
}
Expand Down
6 changes: 4 additions & 2 deletions src/LibLog/LogProviders/LogMessageFormatter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ public static Func<string> SimulateStructuredLogging(Func<string> messageBuilder
return () =>
{
var targetMessage = messageBuilder();
IEnumerable<string> _;
return FormatStructuredMessage(targetMessage, formatParameters, out _);
};
}
Expand All @@ -60,7 +61,8 @@ public static string FormatStructuredMessage(string targetMessage, object[] form
{
var arg = match.Groups["arg"].Value;

if (!int.TryParse(arg, out _))
int result;
if (!int.TryParse(arg, out result))
{
processedArguments = processedArguments ?? new List<string>(formatParameters.Length);
var argumentIndex = processedArguments.IndexOf(arg);
Expand Down Expand Up @@ -88,4 +90,4 @@ public static string FormatStructuredMessage(string targetMessage, object[] form
}
}
}
}
}
2 changes: 1 addition & 1 deletion src/LibLog/LogProviders/LogProviderBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public IDisposable OpenMappedContext(string key, object value, bool destructure
/// <returns>A provider-specific method to open a nested diagnostics context.</returns>
protected virtual OpenNdc GetOpenNdcMethod()
{
return _ => NoopDisposableInstance;
return (_) => NoopDisposableInstance;
}

/// <summary>
Expand Down
11 changes: 9 additions & 2 deletions src/LibLog/LogProviders/NLogLogProvider.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
namespace YourRootNamespace.Logging.LogProviders
{
using System;
using System.Diagnostics.CodeAnalysis;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using System.Linq.Expressions;

Expand All @@ -20,7 +21,12 @@ public NLogLogProvider()
_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)
{
Expand Down Expand Up @@ -283,6 +289,7 @@ public bool Log(LogLevel logLevel, Func<string> messageFunc, Exception exception
var formatMessage = messageFunc();
if (!s_structuredLoggingEnabled)
{
IEnumerable<string> _;
formatMessage =
LogMessageFormatter.FormatStructuredMessage(formatMessage,
formatParameters,
Expand Down
12 changes: 5 additions & 7 deletions src/LibLog/LoggerExecutionWrapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public bool Log(LogLevel logLevel, Func<string> messageFunc, Exception exception
formatParameters);
}

string WrappedMessageFunc()
var WrappedMessageFunc = new Func<string>(() =>
{
try
{
Expand All @@ -61,25 +61,23 @@ string WrappedMessageFunc()
}

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);
}

private interface ICallSiteExtension
{
bool Log(Logger logger, LogLevel logLevel, Func<string> messageFunc, Exception exception,
object[] formatParameters);
bool Log(Logger logger, LogLevel logLevel, Func<string> messageFunc, Exception exception, object[] formatParameters);
}

private class CallSiteExtension : ICallSiteExtension
{
bool ICallSiteExtension.Log(Logger logger, LogLevel logLevel, Func<string> messageFunc, Exception exception,
object[] formatParameters)
bool ICallSiteExtension.Log(Logger logger, LogLevel logLevel, Func<string> messageFunc, Exception exception, object[] formatParameters)
{
return logger(logLevel, messageFunc, exception, formatParameters);
}
}
}
}
}

0 comments on commit 3549f2b

Please sign in to comment.