Log Output--c#

Source: Internet
Author: User

Using system;using system.collections.generic;using system.linq;using system.web;using system.web.mvc;//Add Reference, and import namespaces using system.management;using system.net.networkinformation;using system.io;//log output class   public void Swriter (string ipname)         {            String sfilepath = "D:webtest/logfol der/";//Specify Folder path             String sfilename =" Logoutput "+datetime.now.tostring (" dd ") +". Log ";//Specify file             sFileName = Sfilepath +"/"+ sfilename;//file under specified path     &NBSP ;      //To determine if there is a folder, if not present then create             if (! Directory.Exists (Sfilepath)             {              &N Bsp Directory.CreateDirectory (Sfilepath);           }            FileStream fs;//declaration file flow             StreamwritER sw;//declaration write stream             FileInfo fi=new FileInfo (sfilename);//initialization file Operation class            ///Determine if there is a file and if it does not exist then create             if (!fi. Exists)             {                FS = new FILESTR EAM (sFileName, FileMode.Create, FileAccess.Write);           }        & nbsp   Else {                FS = new FileStream (SFILENAME,FILEMODE.APPEND,FILEACC Ess. Write);           }            FS. Close ();//The stream must be called at the end of the last call. Flush (); with. Close (), method, or diagram is easy to use using to process, you can also use try-catch            using (sw = new StreamWriter (sfilename,true))             {                Console.setout (SW);//Open the file to be written, no this will not be written                 Console.WriteLine ("" "+ Ipname +" "+" IP user "+ DateTime.Now +" access to the homepage!!! ");//write content            }           //streamwriter SW = new Stre Amwriter (@ "D:\WebTest\LogOutput.txt", true);           //console.setout (SW);           //console.writeline ("" "+ Ipname +" "+" IP user "+ DateTime.Now +" access to the homepage!!! ");           //SW. Flush ();           //SW. Close ();       }

Log output--c#

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.