/// <summary> /// Logs a benchmark for all intercepted method calls using the given format string /// /// The format string replaces: /// "%timing%" with the timing in ms. By default uses 2-digit floating point format (e.g. 2.64) /// If an alternative format is desired, pass a format string as specified in https://docs.microsoft.com/en-us/dotnet/standard/base-types/standard-numeric-format-strings /// /// "%method%" with the method signature /// "%args%" with a comma-delimited argument list /// </summary> /// <typeparam name="T"></typeparam> /// <param name="proxii"></param> /// <param name="logLevel">NLog visibility level to log at</param> /// <param name="messageFormat">Format string for message. See method description/docs</param> /// <param name="timingFormat">Formatting to use for the timing parameter</param> /// <returns></returns> public static IProxii <T> LogBenchmark <T>(this IProxii <T> proxii, LogLevel logLevel, string messageFormat, string timingFormat = "F2") where T : class { var logger = typeof(T).GetLogger(); var nLogFormat = messageFormat.Replace("%timing%", "{0}") .Replace("%method%", "{1}") .Replace("%args%", "{2}"); return(proxii.Benchmark(GetLogBenchmarkAction(logger, logLevel, nLogFormat, timingFormat))); }
/// <summary> /// Logs method calls to the configured logger based on a default format. /// /// for MethodSignature level, the format is "called method %method%" /// for Args level, the format is "called method %method% with arguments (%args)" /// /// Method call logging is performed before invocation. /// </summary> /// <typeparam name="T"></typeparam> /// <param name="proxii"></param> /// <param name="detailLevel">The level of information to provide in the log message</param> /// <returns></returns> public static IProxii <T> LogCalls <T>(this IProxii <T> proxii, LogLevel logLevel, MethodCallDetailLevel detailLevel = MethodCallDetailLevel.MethodSignature) where T : class { switch (detailLevel) { case MethodCallDetailLevel.MethodSignature: return(LogCalls(proxii, logLevel, "called method %method%")); case MethodCallDetailLevel.Args: return(LogCalls(proxii, logLevel, "called method %method% with arguments (%args%)")); default: return(proxii); } }
/// <summary> /// Logs method calls to the configured logger using the given format string. /// /// Method call logging is performed before invocation. /// /// The format string replaces: /// "%method%" with the method signature /// "%args%" with a comma-delimited argument list /// </summary> /// <typeparam name="T"></typeparam> /// <param name="proxii"></param> /// <param name="logLevel">The NLog level to log the message to. Defaults to LogLevel.Info</param> /// <param name="format">The format string to use to generate the message</param> /// <returns></returns> public static IProxii <T> LogCalls <T>(this IProxii <T> proxii, LogLevel logLevel, string format) where T : class { var logger = typeof(T).GetLogger(); if (string.IsNullOrWhiteSpace(format)) { logger.Log(LogLevel.Warn, "LogCalls() provided with empty or null format string"); return(proxii); } var nlogFormat = format.Replace("%method%", "{0}") .Replace("%args%", "{1}"); return(proxii.BeforeInvoke(CreateLogCallsAction(logger, logLevel, nlogFormat))); }
/// <summary> /// Logs a benchmark for all intercepted method calls /// using the default format "method %method% took %timing% ms" /// </summary> /// <typeparam name="T"></typeparam> /// <param name="proxii"></param> /// <param name="timingFormat">Formatting to use for the timing parameter</param> /// <returns></returns> public static IProxii <T> LogBenchmark <T>(this IProxii <T> proxii, string timingFormat = "F2") where T : class { return(LogBenchmark(proxii, LogLevel.Info, "method %method% took %timing% ms", timingFormat)); }
/// <summary> /// Logs a benchmark for all intercepted method calls using the given format string /// /// The format string replaces: /// "%timing%" with the timing in ms. By default uses 2-digit floating point format (e.g. 2.64) /// If an alternative format is desired, pass a format string as specified in https://docs.microsoft.com/en-us/dotnet/standard/base-types/standard-numeric-format-strings /// /// "%method%" with the method signature /// "%args%" with a comma-delimited argument list /// </summary> /// <typeparam name="T"></typeparam> /// <param name="proxii"></param> /// <param name="messageFormat">Format string for message. See method description/docs.</param> /// <param name="timingFormat">Formatting to use for the timing parameter</param> /// <returns></returns> public static IProxii <T> LogBenchmark <T>(this IProxii <T> proxii, string messageFormat, string timingFormat) where T : class { return(LogBenchmark(proxii, LogLevel.Info, messageFormat, timingFormat)); }
/// <summary> /// Logs method calls to the configured logger based on a default format. /// /// for MethodName level, the format is "called method %method%" /// for Args level, the format is "called method %method% with arguments (%args)" /// /// Method call logging is performed before invocation. /// </summary> /// <typeparam name="T"></typeparam> /// <param name="proxii"></param> /// <param name="detailLevel">The level of information to provide in the log message</param> /// <returns></returns> public static IProxii <T> LogCalls <T>(this IProxii <T> proxii, MethodCallDetailLevel detailLevel = MethodCallDetailLevel.MethodSignature) where T : class { return(LogCalls(proxii, LogLevel.Info, detailLevel)); }
/// <summary> /// Logs method calls to the configured logger using the given format string. /// /// Method call logging is performed before invocation. /// /// The format string replaces "%method%" with the method signature and /// "%args%" with a comma-delimited argument list /// </summary> /// <typeparam name="T"></typeparam> /// <param name="proxii"></param> /// <param name="logLevel">The NLog level to log the message to. Defaults to LogLevel.Info</param> /// <param name="format">The format string to use to generate the message</param> /// <returns></returns> public static IProxii <T> LogCalls <T>(this IProxii <T> proxii, string format) where T : class { return(LogCalls(proxii, LogLevel.Info, format)); }
public static IProxii <T> LogExceptions <T>(this IProxii <T> proxii, LogLevel logLevel) where T : class { return(proxii.Catch <Exception>(LogExceptionsAction(typeof(T).GetLogger(), logLevel))); }
public static IProxii <T> LogExceptions <T>(this IProxii <T> proxii) where T : class { return(proxii.LogExceptions(LogLevel.Error)); }
/// <summary> /// Logs a JSON object on interception in varying detail levels (https://github.com/zckeyser/proxii-nlog/wiki/LogCallsObject) /// </summary> public static IProxii <T> LogCallsObject <T>(this IProxii <T> proxii, LogDetailLevel detailLevel = LogDetailLevel.Low) where T : class { return(proxii.LogCallsObject(LogLevel.Info, detailLevel)); }
/// <summary> /// Logs a JSON object on interception in varying detail levels (https://github.com/zckeyser/proxii-nlog/wiki/LogCallsObject) /// </summary> public static IProxii <T> LogCallsObject <T>(this IProxii <T> proxii, LogLevel logLevel, LogDetailLevel detailLevel = LogDetailLevel.Low) where T : class { return(proxii.BeforeInvoke(CreateLogCallsObjectAction(typeof(T).GetLogger(), logLevel, detailLevel))); }