Double click to go to source in Output Window

六眼飞鱼酱① 提交于 2019-12-05 00:02:49

I'll just go ahead and answer this by myself then.

To be able to directly jump to the source file, format your message like this:

string.Format("{0}({1})", filePath, lineNumber);

That way, Visual Studio will automatically add the double click functionality and take you directly to the source.

Additionally, if you use the new functionality in Visual Studio 2012, as described here: Caller Details, you can implement your Log Method like this:

private void LogData(string message, 
                     [CallerMemberName] string callerName = "",
                     [CallerLineNumber] int lineNumber = -1,
                     [CallerFilePath] string filePath = "")
    {
        Debug.WriteLine(message);
        Debug.WriteLine(string.Format("    {0}({1})", filePath, lineNumber));
    }

In addition, adding " : error" or ": warning" to the end makes Visual Studio color it red or yellow. If there are any articles describing this further, I'd really like to know.

Well, this question (and answer) appear to be a bit outdated, so let me refresh:

In Visual Studio 2013, the following format is the only one that appears to cause linkage to the file/line that echoed the message:

C#:

{0}({1}): <message here>

For C/C++, give this a whirl:

#define STRINGX(x) #x
#define STRING(x) STRINGX(x)
#define MY_LOG(msg) __pragma(message(__FILE__"(" STRING(__LINE__) "): " msg))

If you don't include the colon after the ending parenthesis, or there is a space between the file name and line number, it will not link to the source code.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!