Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Add line numbers to stack trace of ASP.NET web site that is deployed in release mode

I working on maintenance of one web application, this web site having error log functionality as well.

My client occasionally face some issue on website which also logged in error log file but it shows only method calling hierarchy where exception occurred in stack trace.

When I explicitly raise exception on my Dev environment stack trace of exception shows method calling hierarchy and its line number from where actual exception has occurred.

I know in production we are deploying only DLLs that's why we are not getting error line number in log file.

Anybody has any Idea how can I get error line number as well in exception when we deployed DLL (assemblies) only?

like image 810
Neeraj Kumar Gupta Avatar asked Nov 19 '13 10:11

Neeraj Kumar Gupta


People also ask

How can I get line number in stack trace?

The java. lang. StackTraceElement. getLineNumber() method returns the line number of the source line containing the execution point represented by this stack trace element.


2 Answers

In the build settings, set your project to generate debug symbols (pdb:s) in release mode too. If they are generated they will be automatically included on deploy. There is no need to run the entire site in debug mode, you just need the debug symbols available.

The setting is in the properties of the project. Select the build configuration you are using when publishing. Then on the Build tab, push the Advanced... button and set debug info to "Full".

like image 62
Anders Abel Avatar answered Oct 17 '22 23:10

Anders Abel


The previous answer from Anders Abel perfectly suits your needs. Nevertheless i'd like to add a more architecture-driven approach which is to refactor your log engine to use the new Caller Information attributes from C#5.0

For example you can log exceptions using this method

public static void NDLogException(Exception ex,
               [System.Runtime.CompilerServices.CallerFilePath] string sourceFilePath = "",
               [System.Runtime.CompilerServices.CallerMemberName] string memberName = "",
               [System.Runtime.CompilerServices.CallerLineNumber] int sourceLineNumber = 0)

The compiler will infer and fill in the default arguments with the corresponding values. The attribute CallerLineNumber is the one you're specifically looking for.

Of course this requires you to change your code (assuming it is available to you)

For more information about caller information attributes read here

like image 34
Luis Filipe Avatar answered Oct 18 '22 00:10

Luis Filipe