Advertisement
Guest User

Untitled

a guest
Mar 18th, 2019
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.02 KB | None | 0 0
  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. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement