I have an application that writes/logs the Exception in the database. All codes works okay when I am using the Visual Studio to run the project. But when I compiled or when I created the installer and installed to my PC. The FileName and LineNumber is null. 
I am using the code below:
 var sTrace = new StackTrace(sqlEx, true);
 if (sTrace != null)
  {
    // var frame = sTrace.GetFrame(sTrace.FrameCount - 1);
    var frame = sTrace.GetFrames().Last();
    LineNumber = frame.GetFileLineNumber();
    SrcFileName = frame.GetFileName();
    MethodName = frame.GetMethod().ReflectedType.FullName + "." + frame.GetMethod().Name;
  }
 
    