LogHelper
Posted jbdxbl
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了LogHelper相关的知识,希望对你有一定的参考价值。
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") + " " + "摘要:" + ex.Message + " " + "详细信息:" + ex.StackTrace; byte[] bit = System.Text.Encoding.UTF8.GetBytes(errorinfo); fs.Write(bit, 0, bit.Length); fs.Close(); fs.Dispose(); } } }
以上是关于LogHelper的主要内容,如果未能解决你的问题,请参考以下文章