Registry, and code that records the basic information of the currently calling method

Source: Internet
Author: User

 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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.