/// <summary> /// Log the amount of time an execution takes. The intended usage is to call this method in the /// header of a `using` block to time the interior of the block. /// </summary> /// <param name="logger">The ILogger to log the execution time with.</param> /// <param name="message">The message to log about what has been executed.</param> /// <param name="callerMemberName">The name of the member calling this method.</param> /// <param name="callerFilePath">The file where this method has been called.</param> /// <param name="callerLineNumber">The line number where this method has been called.</param> /// <returns></returns> public static ExecutionTimer LogExecutionTime( this ILogger logger, string message, [CallerMemberName] string callerMemberName = null, [CallerFilePath] string callerFilePath = null, [CallerLineNumber] int callerLineNumber = -1) { return(ExecutionTimer.Start(logger, message, callerMemberName, callerFilePath, callerLineNumber)); }
/// <summary> /// Create a new execution timer and start it. /// </summary> /// <param name="logger">The logger to log the execution timer message in.</param> /// <param name="message">The message to prefix the execution time with.</param> /// <param name="callerMemberName">The name of the calling method or property.</param> /// <param name="callerFilePath">The path to the source file of the caller.</param> /// <param name="callerLineNumber">The line where the timer is called.</param> /// <returns>A new, started execution timer.</returns> public static ExecutionTimer Start( ILogger logger, string message, [CallerMemberName] string callerMemberName = null, [CallerFilePath] string callerFilePath = null, [CallerLineNumber] int callerLineNumber = -1) { var timer = new ExecutionTimer(logger, message, callerMemberName, callerFilePath, callerLineNumber); timer._stopwatch.Start(); return(timer); }