示例#1
0
        /// <summary>
        ///     Writes an event to the logs.
        /// </summary>
        /// <param name="sender">The object that's reporting this event.</param>
        /// <param name="message">The details of the event.</param>
        /// <param name="logType">The type of event that occurred.</param>
        /// <param name="exception">The exception that caused this log.</param>
        internal void WriteEvent(string sender, string message, LogType logType, Exception exception = null)
        {
            if (writerMatrix == null || writerMatrix[(int)logType].Length == 0)
            {
                return;
            }

            string exceptionString = exception?.ToString();

            StringBuilder builder = new StringBuilder(TYPE_PAD + NAME_PAD + 1 + message.Length + (exceptionString?.Length * 2) ?? 0);   //TODO 1 pool object

            builder.Append("[");
            builder.Append(logType.ToString());
            builder.Append("]");
            builder.Append(' ', TYPE_PAD - logType.ToString().Length - 2);
            builder.Append(sender);
            builder.Append(' ', Math.Max(NAME_PAD - sender.Length, 1));

            string[] lines = message.Split('\n');
            builder.Append(lines[0]);
            for (int i = 1; i < lines.Length; i++)
            {
                builder.Append('\n');
                builder.Append(' ', TYPE_PAD + NAME_PAD);
                builder.Append(lines[i]);
            }

            if (exceptionString != null)
            {
                lines = exceptionString.Split('\n');
                for (int i = 0; i < lines.Length; i++)
                {
                    builder.Append('\n');
                    builder.Append(' ', TYPE_PAD + NAME_PAD + 1);
                    builder.Append(lines[i]);
                }
            }

            WriteEventArgs args = new WriteEventArgs(sender, message, logType, exception, builder.ToString(), DateTime.Now);    //TODO 1 pool object

            foreach (LogWriter logWriter in writerMatrix[(int)logType])
            {
                logWriter.WriteEvent(args);
            }
        }
示例#2
0
 /// <summary>
 ///     Writes an event to this log writer.
 /// </summary>
 /// <param name="args">The message to log.</param>
 public abstract void WriteEvent(WriteEventArgs args);
示例#3
0
 public override void WriteEvent(WriteEventArgs args)
 {
     Console.WriteLine(args.FormattedMessage);
 }