Πόσες και πόσες φορές δεν θα θέλαμε το Debug.WriteLine να το έχουμε όταν έχουμε κάνει deploy μια εφαρμογή για να αντιμετωπίσουμε προβλήματα. Το παρακάτω άρθρο πραγματεύεται ένα τρόπο για να έχουμε τα θεμιτά αποτελέσματα.
| Debugging once you go live: Trace Listeners | | I wanted a way to debug our windows forms application once it was deployed to a client machine (Release build). I use Debug.WriteLine and friends when debugging from the IDE, (Debug build) using the Output Window to see my output. How does one do this with a release build though? With the help of the good folks on DOTNET-CLR(at)DISCUSS.DEVELOP.COM, I got this figured out. Trace Listeners and Trace Switches are your friends. I added this to our app.config file: < system.diagnostics> <switches> <!-- Enable/disable profiling messages (0 = disable, 1 = enable) --> <add name="bsProfile" value="1" /> </switches> <trace autoflush="true" indentsize="4"> <listeners> <add name="FileListener" type="System.Diagnostics.TextWriterTraceListener" initializeData=".\AMNETRunTrace.txt" /> </listeners> </trace> </system.diagnostics> When our app loads, I do this: bsProfile = New BooleanSwitch("bsProfile", "Define whether profile information is displayed") Now, when I want to insert some 'debug' statements, I do this: Trace.WriteLineIf(bsProfile.Enabled, "User clicked the Send button") Which says "write 'User clicked the Send button' to the AMNETRunTrace.txt file if <add name="bsProfile" value="1" />" By default, I'll set <add name="bsProfile" value="1" /> If I need to debug something on a user's machine, I'll set it back to 1 (most likely ask them to do this) so I'll see my output in the text file. Once I am done debugging, set it back to 0 and delete the file. You can also output to the Event Log and Output window out of the box, or you could create your own custom listener, like an email listener that sends your support desk an email when something bad happens. Original Link
| |
George J.