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?
The java. lang. StackTraceElement. getLineNumber() method returns the line number of the source line containing the execution point represented by this stack trace element.
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".
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With