国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發設計 > 正文

C#寫文本日志幫助類(支持多線程)

2019-11-17 02:50:10
字體:
來源:轉載
供稿:網友

C#寫文本日志幫助類(支持多線程)

代碼:

using System;using System.Configuration;using System.IO;using System.Threading;namespace FQDService.Utils{    /// <summary>    /// 寫日志類    /// </summary>    public class FileLogger    {        #region 字段        public static readonly object _lock = new object();        #endregion        #region 寫文件        /// <summary>        /// 寫文件        /// </summary>        public static void WriteFile(string log, string path)        {            Thread thread = new Thread(new ParameterizedThreadStart(delegate(object obj)            {                lock (_lock)                {                    if (!File.Exists(path))                    {                        using (FileStream fs = new FileStream(path, FileMode.Create)) { }                    }                    using (FileStream fs = new FileStream(path, FileMode.Append, Fileaccess.Write))                    {                        using (StreamWriter sw = new StreamWriter(fs))                        {                            #region 日志內容                            string value = string.Format(@"{0}--------------------------------------------------------{1}", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), obj.ToString());                            #endregion                            sw.WriteLine(value);                            sw.Flush();                        }                    }                }            }));            thread.Start(log);        }        #endregion        #region 寫日志        /// <summary>        /// 寫日志        /// </summary>        public static void WriteLog(string log)        {            string logPath = ConfigurationManager.AppSettings["LogPath"] + "http://FQDService_Log.txt";            WriteFile(log, logPath);        }        #endregion        #region 寫錯誤日志        /// <summary>        /// 寫錯誤日志        /// </summary>        public static void WriteErrorLog(string log)        {            string logPath = ConfigurationManager.AppSettings["LogPath"] + "http://FQDService_ErrorLog.txt";            WriteFile(log, logPath);        }        #endregion    }}
View Code


發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 西畴县| 南丰县| 临朐县| 朝阳县| 诏安县| 武胜县| 棋牌| 芜湖市| 文昌市| 谢通门县| 岚皋县| 丰原市| 房山区| 湖北省| 庆云县| 报价| 黄梅县| 涿鹿县| 天柱县| 黄山市| 河北省| 新余市| 团风县| 孟津县| 福泉市| 通河县| 确山县| 从江县| 寻乌县| 额济纳旗| 海宁市| 本溪市| 台中县| 涡阳县| 宁河县| 朝阳市| 历史| 靖边县| 如皋市| 新昌县| 军事|