20181015 record a simple TXT log class

Source: Internet
Author: User

Nonsense don't say that directly on the code

usingSystem;usingSystem.Collections.Generic;usingSystem.IO;usingSystem.Linq;usingSystem.Text;usingSystem.Threading.Tasks;namespaceutilities{ Public classTxtloghelper {/// <summary>        ///txt logging of certain operations/// </summary>         Public Static voidLogbackup (stringlogstring) {            stringLogFolder =Getorcreatelogfilepath (); stringLogFile =Getbackuplogfilename (); FileInfo file=NewFileInfo (LogFile); FileStream FS=file.            Open (Filemode.append, FileAccess.Write); byte[] bytes =Encoding.UTF8.GetBytes (logstring); Fs. Write (Bytes,0, Bytes.            Length); Fs.            Flush (); Fs.            Close (); Fs.        Dispose (); }        //Gets the backup directory path, if it does not exist, creates the        Private Static stringGetorcreatelogfilepath () {stringBackupFolder = System.Environment.CurrentDirectory +"\\log"; if(!directory.exists (BackupFolder))            Directory.CreateDirectory (BackupFolder); returnBackupFolder; }        Private Static stringGetbackuplogfilename () {//to prevent excessive data volume, generate a log file daily by date            stringLogfileid = DateTime.Now.ToString ("YYYY-MM-DD"); returnGetorcreatelogfilepath () +"\\"+ Logfileid +". txt"; }    }}

20181015 record a simple TXT log class

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.