• LogHelper类


    纯属个人记录,不供大家学习!

    using System;

    using System.Collections.Generic;

    using System.Linq;

    using System.Text;

    using System.IO;

     

    namespace DPForAD2BPMTel

    {

        public class LogHelper

        {

            #region 写文本日志

     

            /// <summary>

            /// 向日志文件中输出一个空行

            /// </summary>

            public void WriteSpaceLine()

            {

                WriteLog(string.Empty);

            }

     

            /// <summary>

            /// 写日志

            /// </summary>

            /// <param name="message">日志信息</param>

            /// /// <param name="logPath">日志路径</param>

            /// <param name="logName">日志文件名</param>

            public void WriteLog(string message, string logPath, string logName)

            {

                string logMsg = DateTime.Now.ToString("HH:mm:ss \t");

                string logFile = Path.Combine(logPath, logName); // logPath + "\\" + logName; //2008-09-05 修改

                //如果路径不存在,建立目录

                if (!Directory.Exists(logPath))

                {

                    Directory.CreateDirectory(logPath);

                }

                //如果文件不存在,建立文件

                if (!File.Exists(logFile))

                {

                    File.Create(logFile).Close();

                }

     

                logMsg += message;

     

                try

                {

                    WriteToFile(logFile, logMsg);

                }

                catch

                {

                    // do nothing

                }

            }

     

            /// <summary>

            /// 写日志

            /// </summary>

            /// <param name="message">日志信息</param>

            /// /// <param name="logPath">日志路径</param>

            public void WriteLog(string message, string logPath)

            {

                WriteLog(message, logPath, DateTime.Now.ToString("yyyy-MM-dd.LOG"));

            }

     

            /// <summary>

            /// 写日志

            /// </summary>

            /// <param name="sMessage">日志信息</param>

            public void WriteLog(string message)

            {

                WriteLog(message, AppDomain.CurrentDomain.BaseDirectory + "\\LOG");

            }

     

            /// <summary>

            /// 把信息写到指定文件的尾部

            /// </summary>

            /// <param name="fileName">文件完整路径</param>

            /// <param name="msg">信息文本</param>

            public void WriteToFile(string fileName, string msg)

            {

                StreamWriter swWriter = new StreamWriter(new FileStream(fileName, FileMode.Append));

                swWriter.WriteLine(msg);

                swWriter.Close();

            }

            #endregion

        }

    }

     

  • 相关阅读:
    汉明距离
    滑动窗口最大值
    go 携程池限制并发
    【动态UAC权限】无盾程序(win32&cmd)
    屏幕录像专家 爆破注册机 源码
    小程序蒙层滚动禁止穿透,在元素上面添加一个空函数catchtouchmove=preventTouchMove即可
    2021-01-08(今日笔记)
    css 文本超出以省略号显示 与 文本换行
    公众号平台获取关注用户openid列表记
    le5le-topology开发纪要
  • 原文地址:https://www.cnblogs.com/qfb620/p/3117713.html
Copyright © 2020-2023  润新知