コード例 #1
0
        public override void Log(LogData data)
        {
            var message = string.Empty;
            if (writeTimestamp)
            {
                message += data.Time.ToString(CultureInfo.InvariantCulture);
            }

            for (var i = 0; i < data.Indent; i++)
            {
                message += " ";
            }

            if (writeTimestamp && data.Indent <= 0)
            {
                message += " ";
            }

            message += data.ErrorType + "->" + data.Where + " Message:" + data.Message;

            if (data.ErrorType == LogErrorType.Error)
            {
                var color = Console.ForegroundColor;
                Console.ForegroundColor = ConsoleColor.Red;
                Console.WriteLine(message);
                Console.ForegroundColor = color;
            }
            else
            {
                Console.WriteLine(message);
            }
        }
コード例 #2
0
        private void DoLog(LogData data)
        {
            if (data == null)
            {
                throw new ArgumentNullException("data");
            }

            if (!ShouldLog)
            {
                return;
            }

            Log(data);
        }
コード例 #3
0
        public override void Log(LogData data)
        {
            var message = string.Empty;
            if (writeTimestamp)
            {
                message += data.Time.ToString(CultureInfo.InvariantCulture);
            }

            for (var i = 0; i < data.Indent; i++)
            {
                message += " ";
            }

            message += " " + data.ErrorType + "->" + data.Where + " Message:" + data.Message;
            streamWriter.WriteLine(message);
        }
コード例 #4
0
 public abstract void Log(LogData data);
コード例 #5
0
        private static void WriteToLog(string message, string where, LogErrorType type)
        {
            var data = new LogData
            {
                Time = DateTime.Now,
                Message = message,
                Where = @where,
                ErrorType = type,
                Indent = indent
            };

            switch (type)
            {
                case LogErrorType.Information:
                    if (InfromationEvent != null) InfromationEvent(data);
                    break;
                case LogErrorType.Warning:
                    if (WarningEvent != null) WarningEvent(data);
                    break;
                case LogErrorType.Error:
                    if (ErrorEvent != null) ErrorEvent(data);
                    break;
                default:
                    throw new ArgumentOutOfRangeException("type", type, null);
            }
        }