Debug.WriteLine from Logging Assembly in release mode does not write to debug output in Visual Studio

My registration library has a simple DebugLogger that looks like this:

 public class DebugLogger : Logger { protected override void PerformLogging(string entry) { Debug.WriteLine(entry); } } 

The logging library was built in RELEASE mode.

An application that references the registration library is being developed in DEBUG mode, naturally.

The problem is that when an application using the log library calls DebugLogger.PerformLogging("some debug message") nothing is displayed in the debug output of Visual Studio.

I checked that everything works as expected when the logging assembly is built in DEBUG mode.

I expected the input assembly in DEBUG mode to take precedence, but it seems like it is not.

Is there anything that can be done?

Edit

http://msdn.microsoft.com/en-us/library/6x31ezs1.aspx in the notes section refers to the compiler ignores debugging techniques without DEBUG .

+4
source share
3 answers

How the Debug.WriteLine call is Debug.WriteLine is determined when the project containing the call is compiled. In this case, the C # compiler sees the call to Debug.WriteLine in the Release project ( DEBUG not defined) and, therefore, does not pass the call to the received IL. At the moment, the PerformLogging method has no reference to Debug.WriteLine , and therefore, no call from an assembly of any type will make a call to Debug.WriteLine .

+2
source

While you still need to define DEBUG - you do not need to do this from the side. You can only define it in the source files you want. Therefore, if you want to keep a debug log from a specific class, you can define DEBUG only for this source file.

 #define DEBUG using System.Diagnostics; ... class Logger { void Log( string msg ){ Debug.WriteLine( msg ); } } 
+4
source

From http://msdn.microsoft.com/en-us/library/6x31ezs1.aspx

In Visual Studio C # and Visual Basic projects, by default, β€œDEBUG”, the conditional compilation symbol is defined for debug builds, and the β€œTRACE” symbol is defined for both debug build and release.

I created TraceLogger which uses Trace.Writeline and seems to do the trick for me.

I am still open to suggestions.

+1
source

Source: https://habr.com/ru/post/1396225/


All Articles