pumila99
10/24/2016 - 1:28 AM

呼び出し元を取得する (※.NET4.5以上)

呼び出し元を取得する (※.NET4.5以上)

using System.Diagnostics;
using System.Runtime.CompilerServices;

:

public void TraceMessage(string message,
        [CallerMemberName] string memberName = "",
        [CallerFilePath] string sourceFilePath = "",
        [CallerLineNumber] int sourceLineNumber = 0)
{
    Trace.WriteLine("message: " + message);
    Trace.WriteLine("member name: " + memberName);
    Trace.WriteLine("source file path: " + sourceFilePath);
    Trace.WriteLine("source line number: " + sourceLineNumber);
}