zoukankan      html  css  js  c++  java
  • 错误日志编写

     1 using System;
     2 using System.Collections.Generic;
     3 using System.Configuration;
     4 using System.IO;
     5 using System.Linq;
     6 using System.Text;
     7 using System.Threading.Tasks;
     8 
     9 namespace Logs
    10 {
    11     public class ErrorLogs
    12     {
    13         public static void Write(string path,string message, Exception ex)
    14         {
    15             if (path != null && path != "")
    16             {
    17                 if (!(Directory.Exists(path)))
    18                 {
    19                     Directory.CreateDirectory(path); //创建日志文件夹
    20                 }
    21                 path += string.Format(@"\{0}.log", DateTime.Now.ToString("yyyy-MM-dd"));
    22 
    23                 using (var sw = new StreamWriter(path, true, Encoding.Default))
    24                 {
    25                     sw.WriteLine("***********************************************************************************************");
    26                     sw.WriteLine(DateTime.Now.ToString());
    27                     if (ex != null)
    28                     {
    29                         sw.WriteLine("异常信息:");
    30                         sw.WriteLine(message);
    31                         sw.WriteLine("【Message】" + ex.Message);
    32                         sw.WriteLine("【ErrorType】:" + ex.GetType());
    33                         sw.WriteLine("【TargetSite】" + ex.TargetSite);
    34                         sw.WriteLine("【StackTrace】" + ex.StackTrace);
    35                     }
    36                     else sw.WriteLine("Exception Is Null");
    37                     sw.WriteLine();
    38                 }
    39             }
    40         }
    41     }
    42 }
    世界上最可怕事情是比我们优秀的人比我们还努力
  • 相关阅读:
    BeautifulSoup_第一节
    第一个python爬虫——保存淘宝mm图片
    面试题:css(一)
    面试:HTML(二)
    websocket
    面试题:HTML篇(一)
    HTML5遗忘知识点(一)
    webpack热更新原理
    webpack按需加载
    什么是process.env?
  • 原文地址:https://www.cnblogs.com/AlexOneBlogs/p/7287311.html
Copyright © 2011-2022 走看看