/// <inheritdoc />
        public virtual void Write(LogEntry entry)
        {
            int indent = entry.Source.Indent;
            string prefix = entry.Source.Prefix ?? "";
            string[] lines = entry.Message.Split(new[] { '\n', '\r', '\0' }, StringSplitOptions.RemoveEmptyEntries);
            for (int i = 0; i < lines.Length; i++)
            {
                if (i == 0)
                {
                    switch (entry.Type)
                    {
                        case LogMessageType.Message:
                            lines[i] = prefix + "Msg: " + new string(' ', indent * 2) + lines[i];
                            break;
                        case LogMessageType.Warning:
                            lines[i] = prefix + "Wrn: " + new string(' ', indent * 2) + lines[i];
                            break;
                        case LogMessageType.Error:
                            lines[i] = prefix + "ERR: " + new string(' ', indent * 2) + lines[i];
                            break;
                    }
                }
                else
                {
                    lines[i] = new string(' ', prefix.Length + 5 + indent * 2) + lines[i];
                }

                this.WriteLine(entry.Source, entry.Type, lines[i], entry.Context);
            }
        }
			public LogEntryEventArgs(LogEntry entry)
			{
				this.entry = entry;
			}
		private void OnNewEntry(LogEntry entry)
		{
			if (this.NewEntry != null)
				this.NewEntry(this, new LogEntryEventArgs(entry));
		}
		/// <summary>
		/// Writes a single message to the output.
		/// </summary>
		/// <param name="source">The <see cref="Log"/> from which the message originates.</param>
		/// <param name="type">The type of the log message.</param>
		/// <param name="msg">The message to write.</param>
		public void Write(Log source, LogMessageType type, string msg)
		{
			LogEntry entry;
			entry = new LogEntry(source, type, msg);
			data.Add(entry);
			this.OnNewEntry(entry);
		}
示例#5
0
文件: Log.cs 项目: SirePi/duality
        private void Write(LogMessageType type, string msg, object context)
        {
            Profile.TimeLog.BeginMeasure();

            // If a null message is provided, log that. Don't throw an exception, since logging isn't expected to throw.
            if (msg == null) msg = "[null message]";

            // Check whether the message contains null characters. If it does, crop it, because it's probably broken.
            int nullCharIndex = msg.IndexOf('\0');
            if (nullCharIndex != -1)
            {
                msg = msg.Substring(0, Math.Min(nullCharIndex, 50)) + " | Contains '\0' and is likely broken.";
            }

            // Forward the message to all outputs
            LogEntry entry = new LogEntry(this, type, msg, context);
            foreach (ILogOutput log in this.strOut)
            {
                try
                {
                    log.Write(entry);
                }
                catch (Exception)
                {
                    // Don't allow log outputs to throw unhandled exceptions,
                    // because they would result in another log - and more exceptions.
                }
            }
            Profile.TimeLog.EndMeasure();
        }
示例#6
0
 /// <inheritdoc />
 public void Write(LogEntry entry)
 {
     data.Add(entry);
 }