c# - Nothing shows up in my log file -


i trying create logger logs stack trace text file, "log.txt". when run code, blank log.txt document created in directory, nothing being written in txt file.

my following code following:

public void log()     {         // create file output .txt.         stream debugfile = file.create(@"c:\temp\log.txt");         // create textwritertracelistener named "file"         textwritertracelistener debugwriter = new textwritertracelistener(debugfile, "file");         // add debug listeners         debug.listeners.add(debugwriter);         // set callstack shown         debug.listeners["file"].traceoutputoptions |= traceoptions.callstack;         // set auto-flush         debug.autoflush = true;         debug.writeline("message: " + environment.stacktrace);         debugfile.close();     } 

make sure 'define debug constant' checkbox checked in project's properties > build section.

it's defined constant, though microsoft cryptically calls them 'conditional compilation symbols'... vs stuff depending on whether trace or debug defined (like allow writing out debug or trace listeners). in way, can write debug helpers want files, , long surrounded #if , #endif, once you're ready deploy program don't define constants, , compiler ignore (not compile) sections of code.

you can define own constants. type conditional compilation symbols box following: "sendlogging". in code, can

private void log() {     #if locallogging     //write file      #elif sendlogging     //send email relevant info     #else     //do other stuff     #endif } 

in case, middle section run. had defined locallogging, first block run.

more reading: https://msdn.microsoft.com/en-us/library/0feaad6z.aspx


Comments

Popular posts from this blog

Android : Making Listview full screen -

javascript - Parse JSON from the body of the POST -

javascript - How to Hide Date Menu from Datepicker in yii2 -