zoukankan      html  css  js  c++  java
  • 简单日志LogHelper

     public static class LogHelper
        {
            //日志存储路径
            private static string LogPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, System.Configuration.ConfigurationManager.AppSettings["LogPath"]);
    
            private static object LogLock = new object();//日志锁
    
            /// <summary>
            /// 添加正常信息
            /// </summary>
            /// <param name="message"></param>
            public static void AddInfo(string message)
            {
                string fileName = DateTime.Now.ToString("yyyyMMdd") + ".txt";//日志名称
                string fullName = Path.Combine(LogPath, fileName);
    
                lock (LogLock)
                {
                    if (!Directory.Exists(LogPath))//如果目录不存在 创建目录
                    {
                        Directory.CreateDirectory(LogPath);
                    }
                    using (var stream = File.AppendText(fullName))
                    {
                        stream.WriteLine(message);
                    }
                    Console.WriteLine(message);
                }
            }
    
            /// <summary>
            /// 添加错误信息
            /// </summary>
            /// <param name="errorMessage"></param>
            public static void AddError(string errorMessage)
            {
                string fileName ="Error_"+ DateTime.Now.ToString("yyyyMMdd") + ".txt";//日志名称
                string fullName = Path.Combine(LogPath, fileName);
    
                lock (LogLock)
                {
                    if (!Directory.Exists(LogPath))//如果目录不存在 创建目录
                    {
                        Directory.CreateDirectory(LogPath);
                    }
                    using (var stream = File.AppendText(fullName))
                    {
                        stream.WriteLine(errorMessage);
                    }
                    Console.WriteLine(errorMessage);
                }
            }
        }
  • 相关阅读:
    CF1391D 【505】
    CF1389C 【Good String】
    CF1364C 【Ehab and Prefix MEXs】
    CF1353E 【K-periodic Garland】
    CF1349A 【Orac and LCM】
    CF1352C 【K-th Not Divisible by n】
    CF413D 【2048】
    CF257B 【Playing Cubes】
    CF267A 【Subtractions】
    2018.8.16提高B组模拟考试
  • 原文地址:https://www.cnblogs.com/marshhu/p/6780138.html
Copyright © 2011-2022 走看看