About log files in the project

It can be said that only when one person carries the project will you have a real improvement. Before, I have never used handwritten log documents to record what kind of problems in the project. However, recently, when one person is playing the project, he still connects with other companies with the api interface. The callback function is because there is no way to do it or debug it, and you can't see what the obtained data looks like. You can only write a log file to check the parameters that are called back. The code below is for those of you who are about to, or have had problems:

public void Write(string test)
    {


        string path = Server.MapPath(".") + "\\log\\" + "bank.xml"; this is whether the xml exists in the folder of the current file of your project, if not, create it, 15 is from \ The length of the string from \log to xml is different. If you have another name, just count it and replace it with 15.
        if (Directory.Exists(path.Substring(0, path.Length - 15)) == false)//Determine whether there is already a file name under such a path
        {
            Directory.CreateDirectory(path.Substring(0, path.Length - 15));//Create folder does not exist
        }
        StreamWriter sw = new StreamWriter(path, true, Encoding.Default);
        sw.WriteLine(DateTime.Now.ToString());
        sw.WriteLine(test);
        sw. Close();
    }


Needless to say about the final call, you can directly bring the data you want to see in the method name. If there is no writing in the project, then you can check whether your folder has permission to be accessed by everyone. If you don't have permission, you can't write in.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326028462&siteId=291194637