Hello,
Welcome to Microsoft Q&A!
I've made a test in a C++/CX UWP application, the OutputDebugString
function works correctly in both debug and release mode. Then I tried other applications like C# WPF applications and C# console applications. The win32 function doesn't work in these applications in both debug and release mode. So this might be an issue related to the C# language. But the reason for this behavior is still unclear.
Now a workaround for this scenario is that you could use a macro to run different debug functions in different modes. When running in debug mode, the app will automatically use the System.Diagnostics.Debug.WriteLine
function. When running in release mode, the app will run OutputDebugString
function instead.
Like this:
private void Button_Click(object sender, RoutedEventArgs e)
{
#if DEBUG
// Debug work here
System.Diagnostics.Debug.WriteLine("Debug output info.");
#else
// Release work here
OutputDebugString("Debug output info.");
#endif
}
Thank you.
If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.