Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /// <summary>
- /// For easily logging a method's name with In, Out and Info options.
- /// </summary>
- /// <remarks>
- /// This works in async methods and doesn't mind being called from a lambda which `StackFrame` will fail on.
- /// </remarks>
- /// <usage>
- /// Log.Information(LogMethodInfo.In());
- /// Log.Information($"{LogMethodInfo.Info()} | Creating temporary file '{tempFileName}' for file {file.ImportedFileUid}");
- /// </usage>
- public class LogMethodInfo
- {
- public static string In([CallerMemberName] string memberName = "") => $"## In ## {LogDetails(memberName)}";
- public static string Out([CallerMemberName] string memberName = "") => $"## Out ## {LogDetails(memberName)}";
- public static string Info(string action = null, [CallerMemberName] string memberName = "") => $"{(action != null ? "## " + action + " ## " : "")}{LogDetails(memberName)}";
- private static string LogDetails(string methodName) => $"{methodName}() [{Thread.CurrentThread.ManagedThreadId}]";
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement