C# 错误日志中未打印行号

C# 错误日志中未打印行号,c#,error-handling,exception-handling,C#,Error Handling,Exception Handling,我有一个控制器的异常处理属性,它为程序中出现的每个异常写入错误日志。我在服务器上部署了.pdb文件,并为行号编写了以下代码: // Get stack trace for the exception with source file information var st = new StackTrace(ex, true); // Get the top stack frame var frame = st.GetFrame(0); // Get the line number from the

我有一个控制器的异常处理属性,它为程序中出现的每个异常写入错误日志。我在服务器上部署了.pdb文件,并为行号编写了以下代码:

// Get stack trace for the exception with source file information
var st = new StackTrace(ex, true);
// Get the top stack frame
var frame = st.GetFrame(0);
// Get the line number from the stack frame
var line = frame.GetFileLineNumber();
我还是得到了行号为0

关于这一点,我有两个问题:

  • 如果我将.pdb文件保存在服务器上,行号不应该自动写入吗
  • 为什么我在上面的代码中将它们设为0
  • 我提到


    感谢您的回复。

    不一定;尽管有PDB,但代码可能经过了优化,无法将堆栈中的特定点与源代码中的任何一个行号相关联。@Jenish:我已经在服务器上安装了带有二进制文件的.PDB。@Peter:我还有什么选择?@Mustafa是否检查了ex.StackTrace(字符串)是否包含行号?@Jenish:没有。我打印完整的堆栈跟踪,但其中没有行号。