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

Commit

Permalink
Update .pp files
Browse files Browse the repository at this point in the history
  • Loading branch information
damianh committed Jan 6, 2019
1 parent 8c06287 commit 2a8ecfb
Show file tree
Hide file tree
Showing 8 changed files with 35 additions and 21 deletions.
11 changes: 5 additions & 6 deletions src/LibLog/LogExtensions.cs.pp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -530,8 +530,7 @@
// 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 @@ -543,18 +542,18 @@
}

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.pp
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,10 @@
}
}

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

/// <summary>
/// Gets a logger for the specified type.
Expand All @@ -126,7 +129,10 @@
#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 @@ -298,7 +304,9 @@
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.pp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

public void Dispose()
{
_onDispose?.Invoke();
if(_onDispose != null) _onDispose.Invoke();
}
}
}
2 changes: 1 addition & 1 deletion src/LibLog/LogProviders/Log4NetLogProvider.cs.pp
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,7 @@
case LogLevel.Fatal:
return s_levelFatal;
default:
throw new ArgumentOutOfRangeException(nameof(logLevel), logLevel, null);
throw new ArgumentOutOfRangeException("logLevel", logLevel, null);
}
}
}
Expand Down
4 changes: 3 additions & 1 deletion src/LibLog/LogProviders/LogMessageFormatter.cs.pp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
return () =>
{
var targetMessage = messageBuilder();
IEnumerable<string> _;
return FormatStructuredMessage(targetMessage, formatParameters, out _);
};
}
Expand All @@ -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<string>(formatParameters.Length);
var argumentIndex = processedArguments.IndexOf(arg);
Expand Down
2 changes: 1 addition & 1 deletion src/LibLog/LogProviders/LogProviderBase.cs.pp
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@
/// <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.pp
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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)
{
Expand Down Expand Up @@ -284,6 +290,7 @@
var formatMessage = messageFunc();
if (!s_structuredLoggingEnabled)
{
IEnumerable<string> _;
formatMessage =
LogMessageFormatter.FormatStructuredMessage(formatMessage,
formatParameters,
Expand Down
10 changes: 4 additions & 6 deletions src/LibLog/LoggerExecutionWrapper.cs.pp
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
formatParameters);
}

string WrappedMessageFunc()
var WrappedMessageFunc = new Func<string>(() =>
{
try
{
Expand All @@ -62,22 +62,20 @@
}

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

0 comments on commit 2a8ecfb

Please sign in to comment.