Frage

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?

War es hilfreich?

Lösung

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".

Andere Tipps

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

That's new feature in c#5, you can do this for example :

public class LogManager
{
    public void LogException(Exception exc,
                            [CallerMemberName] string memberName = "",
                            [CallerFilePath] string sourceFilePath = "",
                            [CallerLineNumber] int sourceLineNumber = 0)
    {
        Trace.WriteLine(string.Format("Date: {0}", DateTime.Now));
        Trace.WriteLine(string.Format("Exception: {0}", exc.Message));
        Trace.WriteLine(string.Format("Occured in: {0}", memberName));
        Trace.WriteLine(string.Format("source file path: {0}", sourceFilePath));
        Trace.WriteLine(string.Format("source line number: {0}", sourceLineNumber));
    }
}
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top