private static string GetParameters(MethodCallParameters parameters) { string result = string.Empty; if (parameters is not null) { bool isFirst = true; foreach (var kvPair in parameters) { if (!isFirst) { result += ", "; } isFirst = false; result += kvPair.Key + "="; if (kvPair.Value is null) { result += "Null"; } else { result += kvPair.Value switch { string str => $"'{kvPair.Value}'", List <string> list => $"[{string.Join(",", list)}]", string[] strings => $"[{string.Join(",", strings)}]", _ => $"{kvPair.Value}", }; } } } return(result); }
public static IDisposable MethodCall <TEntity, TRelatedEntity>(Type type, MethodCallParameters parameters = null, [CallerMemberName] string methodName = "") { var method = MethodCalls.MethodSignature(type, typeof(TEntity), typeof(TRelatedEntity), methodName, parameters); var result = LogContext.PushProperty("Method", method); Log.Verbose(method); return(result); }
public static string MethodSignature(Type type, string methodName, MethodCallParameters parameters = null) { if (type is null) { throw new ArgumentNullException(nameof(type)); } #if NET472 return($"{GetTypeName(type)}.{methodName}({GetParameters(parameters)})".Replace("..", ".")); #else return($"{GetTypeName(type)}.{methodName}({GetParameters(parameters)})".Replace("..", ".", StringComparison.CurrentCultureIgnoreCase)); #endif }
public static IDisposable MethodCall <T, TEntity, TRelatedEntity>(this ILogger <T> logger, Type type, MethodCallParameters parameters = null, [CallerMemberName] string methodName = "") { logger.LogDebug(MethodCalls.MethodSignature(type, typeof(TEntity), typeof(TRelatedEntity), methodName, parameters)); return(SAEONLogs.MethodCall <TEntity, TRelatedEntity>(type, parameters, methodName)); }
public static IDisposable MethodCall(this ILogger logger, Type type, MethodCallParameters parameters = null, [CallerMemberName] string methodName = "") { logger.LogDebug(MethodCalls.MethodSignature(type, methodName, parameters)); return(SAEONLogs.MethodCall(type, parameters, methodName)); }