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);
            }
        }
        private void DoLog(LogData data)
        {
            if (data == null)
            {
                throw new ArgumentNullException("data");
            }

            if (!ShouldLog)
            {
                return;
            }

            Log(data);
        }
        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);
        }
 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);
            }
        }