Debug.WriteLine in release build

后端 未结 4 1190
[愿得一人]
[愿得一人] 2020-12-13 17:15

Is there a way to use Debug.WriteLine in a release build without defining DEBUG?

4条回答
  •  遥遥无期
    2020-12-13 17:41

    While you still have to define DEBUG - you don't have to do it assembly wide. You can define it only in the source files that you want. So if you want debug logging from a particular class you can define DEBUG just for that source file.

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

提交回复
热议问题