コード例 #1
0
ファイル: LoggerUtility.cs プロジェクト: iLuffy/ILuffy
        private static void AddMessage(LoggerMessage message)
        {
            lock (Logger)
            {
                if (manualWriteLogEvent == null)
                {
                    manualWriteLogEvent = new ManualResetEvent(false);
                }

                if (innerThread == null || innerThread.ThreadState == System.Threading.ThreadState.Stopped)
                {
                    innerThread = new Thread(WriteLogs);
                    innerThread.IsBackground = true;
                    innerThread.Start();
                }

                if (messages == null)
                {
                    messages = new List<LoggerMessage>() { message };
                }
                else
                {
                    messages.Add(message);

                    if (messages.Count > IOPConfig.Configuration.Logger.MaxLoggers)
                    {
                        manualWriteLogEvent.Set();
                    }
                }
            }
        }
コード例 #2
0
ファイル: LoggerUtility.cs プロジェクト: iLuffy/ILuffy
        /// <summary>
        /// Write message
        /// </summary>
        /// <param name="severity"></param>
        /// <param name="format"></param>
        /// <param name="objs"></param>
        /// <returns></returns>
        public static bool WriteMessage(Severity severity, string format, params object[] objs)
        {
            var logger = Logger;
            if (logger != null && logger.CurrentSeverity <= severity)
            {
                var message = format;

                if (objs != null && objs.Length > 0)
                {
                    message = string.Format(format, objs);
                }

                var loggerMessage = new LoggerMessage(severity, 
                    Thread.CurrentThread.ManagedThreadId, 
                    Thread.CurrentThread.Name, message);

                if (IOPConfig.Configuration.Logger.IsMultipleThreadEnabled)
                {
                    AddMessage(loggerMessage);
                }
                else
                {
                    logger.WriteMessage(loggerMessage);
                }

                return true;
            }

            return false;
        }