• 错误日志编写


     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 }
    世界上最可怕事情是比我们优秀的人比我们还努力
  • 相关阅读:
    P2519 [HAOI2011]problem a
    P1084 疫情控制
    P1941 飞扬的小鸟
    NOIP填坑计划
    P2831 愤怒的小鸟
    AGC 16 D
    P3960 列队
    Python3爬虫相关软件,库的安装
    软件理论基础—— 第一章命题逻辑系统L
    软件理论基础——导论
  • 原文地址:https://www.cnblogs.com/AlexOneBlogs/p/7287311.html
Copyright © 2020-2023  润新知