Public classTeststacktrace {List<Object> Paramvalueitems =Newlist<Object>(); Public voidTestMethod (intNumstringmsg) { //writing to the registryRegistryKey RK =Registry.localmachine; Rk. SetValue ("Lolregister"," Do"); //record the value of a method parameterparamvalueitems.clear (); Paramvalueitems.add (num); Paramvalueitems.add (msg); Writelog (Paramvalueitems); Num+=num; Msg= num. ToString () +"Hello Word"; } Public voidWritelog (list<Object>items) { Try { //If you can output the log, execute//if (Isenableoutputlog = = True)//{StackTrace st =NewStackTrace (true); //The parameters in this parenthesis start with 0, 0 is yourself, and 1 is the lastMethodBase methodName = St. GetFrame (1). GetMethod (); //get the Parameter collectionparameterinfo[] Paraminfo = St. GetFrame (1). GetMethod (). GetParameters (); //file path stringFileName ="MethodInfoLog.txt"; //defining file Information ObjectsFileInfo Finfo =NewFileInfo (fileName); //determine if the file exists and is greater than 2M 2048000 if(Finfo. Exists && Finfo. Length >2048000) { Try { //Delete the fileFinfo. Delete (); } Catch(Exception e) {}}using(StreamWriter writer =NewStreamWriter (FileName,true, System.Text.Encoding.UTF8,1024x768) {writer. WriteLine ("Method Name:"+methodname.name); Writer. WriteLine ("Call time:"+DateTime.Now); Writer. WriteLine ("--------------------------------------------------------------------"); for(inti =0; I < items. Count; i++) {writer. WriteLine ("parameter name:"+Paraminfo[i]. Name); Writer. WriteLine ("parameter type:"+Paraminfo[i]. ParameterType); Writer. WriteLine ("parameter values:"+Items[i]. ToString ()); Writer. WriteLine ("parameter location:"+Paraminfo[i]. Position); Writer. WriteLine (String.Empty); Writer. WriteLine ("*********************************************************************"); Writer. Flush (); Writer. Close (); } } //} } Catch(Exception ex) {//Writelog (Ex, "Method records an exception!) "); } }
Registry, and code that records the basic information of the currently calling method