Beispiel #1
0
 /// <summary>
 ///   静态构造
 /// </summary>
 static LogRecorder()
 {
     _isTextRecorder = true;
     Recorder        = BaseRecorder = new TxtRecorder();
     BaseRecorder.Initialize();
     Task.Factory.StartNew(WriteRecordLoop);
 }
Beispiel #2
0
        /// <summary>
        ///   静态构造
        /// </summary>
        static LogRecorder()
        {
            Recorder = new TxtRecorder();
            Recorder.Initialize();
            var logThread = new Thread(WriteRecordLoop)
            {
                IsBackground = true, Priority = ThreadPriority.Lowest
            };

            logThread.Start();
        }
Beispiel #3
0
        /// <summary>
        ///   静态构造
        /// </summary>
        static LogRecorder()
        {
            Recorder = BaseRecorder = new TxtRecorder();
            Recorder.Initialize();
            _isTextRecorder = true;
            var logThread = new Thread(WriteRecordLoop)
            {
                IsBackground = true,
                Priority     = ThreadPriority.BelowNormal
            };

            logThread.Start();
        }
Beispiel #4
0
        /// <summary>
        ///   静态构造
        /// </summary>
        static LogRecorder()
        {
            Enum.TryParse(ConfigurationManager.AppSettings["LogLevel"] ?? "Trace", out LogLevel);

            Recorder = BaseRecorder = new TxtRecorder();
            Recorder.Initialize();
            IsTextRecorder = true;
            var logThread = new Thread(WriteRecordLoop)
            {
                IsBackground = true,
                Priority     = ThreadPriority.Lowest
            };

            logThread.Start();
        }
Beispiel #5
0
        // ReSharper restore FunctionNeverReturns

        private static void WriteToLog(RecordInfo info)
        {
            try
            {
                if (Listener != null)
                {
                    Listener.Trace(info);
                    Thread.Sleep(0);
                }
                else
                {
                    SystemTrace(info.Message);
                }
            }
            catch (Exception ex)
            {
                SystemTrace("日志侦听器发生错误", ex);
            }
            try
            {
                if (info.Type == LogType.Trace)
                {
                    TxtRecorder.RecordTrace(info.Message);
                    return;
                }
                if (info.Type == LogType.Monitor)
                {
                    TxtRecorder.RecordTrace(info.Message, ".monitor");
                    return;
                }
#if SERVICE
                if ((info.Type == LogType.Error || info.Type == LogType.Exception) && !IsTextRecorder)
                {
                    TxtRecorder.Recorder.RecordLog(info);
                }
                Recorder?.RecordLog(info);
#else
                Recorder.RecordLog(info);
#endif
            }
            catch (Exception ex)
            {
                SystemTrace("日志写入发生错误", ex);
            }
        }
Beispiel #6
0
        // ReSharper restore FunctionNeverReturns

        private static void WriteToLog(RecordInfo info)
        {
            try
            {
                if (Listener != null)
                {
                    Listener.Trace(info);
                    Thread.SpinWait(0);
                }
                else
                {
                    SystemTrace(info.Message);
                }
            }
            catch (Exception ex)
            {
                SystemTrace("日志侦听器发生错误", ex);
            }
            try
            {
                switch (info.Type)
                {
                case LogType.Trace:
                    TxtRecorder.RecordTrace(info.Message);
                    return;

                case LogType.Monitor:
                    TxtRecorder.RecordTrace(info.Message, ".monitor");
                    return;
                }
                if (!IsTextRecorder && info.Type > LogType.System)
                {
                    BaseRecorder.RecordLog(info);
                }
                Recorder.RecordLog(info);
            }
            catch (Exception ex)
            {
                SystemTrace("日志写入发生错误", ex);
            }
        }