Private voidBtnexception_click (Objectsender, EventArgs e) { Try { Throw NewException ("Anomaly Testing"); } Catch(Exception ex) {M_writelog (ex); } finally { } } voidM_writelog (Exception ex,stringlogaddress="") { //If the log file is empty, the new Yyyy-mm-dd_log.log file is created by default in the Debug directory if(Logaddress = ="") {logaddress= Environment.currentdirectory +'\\'+ DateTime.Now.Year +'-'+ DateTime.Now.Month +'-'+ DateTime.Now.Day +"_log.log"; } //output exception information to a fileStreamWriter SW =NewStreamWriter (Logaddress,true); Sw. WriteLine ("Current Time:"+DateTime.Now.ToString ()); Sw. WriteLine ("Exception Information:"+Ex. Message); Sw. WriteLine ("Exception object:"+Ex. Source); Sw. WriteLine ("Call stack: \ n"+Ex. Stacktrace.trim ()); Sw. WriteLine ("Trigger Method:"+Ex. TargetSite); Sw. WriteLine (); Sw. Close (); }
Exception automatically catch the object with exception, the object has the exception information, everything is the idea of the object is worthy of recognition, the exception information pop out of the error box is also a GUI drawing objects drawn out of the dialog box
Mastering the connotation of a technology can be dynamic handwritten code, mastering the various namespaces about what to do, the class under the namespace is concrete implementation, with the constructor event delegate method attributes and other class members to achieve the desired function and
The purpose of the effect.
Write Exception Log