zoukankan      html  css  js  c++  java
  • 系统日志类

    public class LogManager
    {
        
    private static string logPath = string.Empty;
        
    /// <summary>
        
    /// 保存日志的文件夹
        
    /// </summary>
        public static string LogPath
        {
            
    get
            {
                
    if (logPath == string.Empty)
                {
                    
    if (System.Web.HttpContext.Current == null)
                        
    // Windows Forms 应用
                        logPath = AppDomain.CurrentDomain.BaseDirectory;
                    
    else
                        
    // Web 应用
                        logPath = AppDomain.CurrentDomain.BaseDirectory + @"bin\";
                }
                
    return logPath;
            }
            
    set{ logPath = value;}
        }

        
    private static string logFielPrefix = string.Empty;
        
    /// <summary>
        
    /// 日志文件前缀
        
    /// </summary>
        public static string LogFielPrefix
        {
            
    get { return logFielPrefix; }
            
    set { logFielPrefix = value; }
        }

        
    /// <summary>
        
    /// 写日志
        
    /// </summary>
        public static void WriteLog(string logFile, string msg)
        {
            
    try
            {
                System.IO.StreamWriter sw 
    = System.IO.File.AppendText(
                    LogPath 
    + LogFielPrefix + logFile + " " + 
                    DateTime.Now.ToString(
    "yyyyMMdd"+ ".Log"
                    );
                sw.WriteLine(DateTime.Now.ToString(
    "yyyy-MM-dd HH:mm:ss: "+ msg);
                sw.Close();
            }
            
    catch
            { }
        }

        
    /// <summary>
        
    /// 写日志
        
    /// </summary>
        public static void WriteLog(LogFile logFile, string msg)
        {
            WriteLog(logFile.ToString(), msg);
        }
    }

    /// <summary>
    /// 日志类型
    /// </summary>
    public enum LogFile
    {
        Trace,
        Warning,
        Error,
        SQL
    }
  • 相关阅读:
    iOS new Date() 报invalid Date
    Windows查找端口对应进程
    Dbvisualizer Free版本无sql自动提示功能解决方案
    Docker
    更换k8s集群,或者创建集群使用用户不对,导致ranchar无法显示容器处理
    linux下mysql5.7.30安装
    ansible 使用redis缓存
    tr命令
    ipvsadm安装配置NAT
    2019新电脑主板安装win10系统
  • 原文地址:https://www.cnblogs.com/cxlings/p/3079779.html
Copyright © 2011-2022 走看看