首页 > 其他 > 详细

LogHelper

时间:2018-08-03 22:24:46      阅读:151      评论:0      收藏:0      [点我收藏+]
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.IO;

namespace MvcApplication1.Common
{
    public class LogHelper
    {
        public static void WriteError(Exception ex)
        {
            string path = HttpContext.Current.Server.MapPath("~/Logs/" + DateTime.Now.ToString("yyyy-MM-dd") + ".text");
            FileStream fs;
            if (File.Exists(path))
            {
                fs = new FileStream(path, FileMode.Append, FileAccess.Write);
            }
            else
            {
                fs = File.Create(path);
            }
            string errorinfo = "日期:" + DateTime.Now.ToString("hh:mm:ss") + "\r\n" + "摘要:" + ex.Message + "\r\n" + "详细信息:" + ex.StackTrace;
            byte[] bit = System.Text.Encoding.UTF8.GetBytes(errorinfo);
            fs.Write(bit, 0, bit.Length);
            fs.Close();
            fs.Dispose();

        }
    }
}

 

LogHelper

原文:https://www.cnblogs.com/jbdxbl/p/9416397.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!