Esempio n. 1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="logPath"></param>
        /// <param name="msg"></param>
        /// <param name="exception"></param>
        public void WriterLog(String logPath, Object msg, Exception exception = null)
        {
            CommUtil.ResetLogDirectory(logPath);
            WriterFile wfile  = new WriterFile(logPath);
            String     logmsg = GetLogString("FILE ", msg, exception, 2);

            wfile.Writer(logmsg);
            wfile.Close();
        }
Esempio n. 2
0
        /// <summary>
        /// 增加日志
        /// </summary>
        /// <param name="level"></param>
        /// <param name="msg"></param>
        /// <param name="exception"></param>
        void AddLog(string level, Object msg, Exception exception)
        {
            string logmsg = GetLogString(level, msg, exception, 3);

            if (exception != null)
            {
                if (CommUtil.LOG_PRINT_FILE)
                {
                    /*处理如果有异常,需要把异常信息打印到单独的文本文件*/
                    if (wfileerror == null)
                    {
                        lock (typeof(WriterFile))
                            if (wfileerror == null)
                            {
                                /*双重判定单例模式,防止并发*/
                                wfileerror = new WriterFile(CommUtil.LOGPATH, "log-error-file", true);
                            }
                    }
                    wfileerror.Add(logmsg);
                }
            }
            if (CommUtil.LOG_PRINT_FILE)
            {
                /*处理到日志文件*/
                if (wfile == null)
                {
                    lock (typeof(WriterFile))
                        if (wfile == null)
                        {
                            /*双重判定单例模式,防止并发*/
                            wfile = new WriterFile(CommUtil.LOGPATH, "log-file", false);
                        }
                }
                wfile.Add(logmsg);
            }
            if (CommUtil.LOG_PRINT_CONSOLE)
            {
                /*处理到控制台*/
                if (wconsole == null)
                {
                    lock (typeof(WriterFile))
                        if (wconsole == null)
                        {
                            /*双重判定单例模式,防止并发*/
                            wconsole = new WriterConsole("log-console");
                        }
                }
                wconsole.Add(logmsg);
            }
        }