SHARE
TWEET

Untitled

a guest Mar 18th, 2019 59 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /// <summary>
  2.     /// For easily logging a method's name with In, Out and Info options.
  3.     /// </summary>
  4.     /// <remarks>
  5.     /// This works in async methods and doesn't mind being called from a lambda which `StackFrame` will fail on.
  6.     /// </remarks>
  7.     /// <usage>
  8.     /// Log.Information(LogMethodInfo.In());
  9.     /// Log.Information($"{LogMethodInfo.Info()} | Creating temporary file '{tempFileName}' for file {file.ImportedFileUid}");
  10.     /// </usage>
  11.     public class LogMethodInfo
  12.     {
  13.         public static string In([CallerMemberName] string memberName = "") => $"## In ## {LogDetails(memberName)}";
  14.         public static string Out([CallerMemberName] string memberName = "") => $"## Out ## {LogDetails(memberName)}";
  15.         public static string Info(string action = null, [CallerMemberName] string memberName = "") => $"{(action != null ? "## " + action + " ## " : "")}{LogDetails(memberName)}";
  16.  
  17.         private static string LogDetails(string methodName) => $"{methodName}() [{Thread.CurrentThread.ManagedThreadId}]";
  18.     }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top