示例#1
0
		/// <summary>
		/// To record a message.
		/// </summary>
		/// <param name="message">A debug message.</param>
		protected override void OnWriteMessage(LogMessage message)
		{
			if (message.IsDispose)
			{
				Dispose();
				return;
			}

			ConsoleColor color;

			switch (message.Level)
			{
				case LogLevels.Debug:
				case LogLevels.Info:
					color = ConsoleHelper.Info;
					break;
				case LogLevels.Warning:
					color = ConsoleHelper.Warning;
					break;
				case LogLevels.Error:
					color = ConsoleHelper.Error;
					break;
				default:
					throw new ArgumentOutOfRangeException(nameof(message));
			}

			var newLine = "{0} | {1, -15} | {2}".Put(message.Time.ToString(TimeFormat), message.Source.Name, message.Message);

			newLine.ConsoleWithColor(color);
		}
示例#2
0
		/// <summary>
		/// To create a header.
		/// </summary>
		/// <param name="message">A debug message.</param>
		/// <returns>Header.</returns>
		protected virtual string GetSubject(LogMessage message)
		{
			if (message == null)
				throw new ArgumentNullException("message");

			return message.Source.Name + " " + message.Level + " " + message.Time.ToString(TimeFormat);
		}
示例#3
0
 public void AddLog(LogMessage message)
 {
     if (this.Log != null)
     {
         this.Log(message);
     }
 }
示例#4
0
		/// <summary>
		/// To add a message in a queue for sending.
		/// </summary>
		/// <param name="message">Message.</param>
		private void EnqueueMessage(LogMessage message)
		{
			if (message.IsDispose)
			{
				Dispose();
				return;
			}

			_queue.Enqueue(Tuple.Create(GetSubject(message), message.Message));

			lock (_queue.SyncRoot)
			{
				if (_isThreadStarted)
					return;

				_isThreadStarted = true;

				ThreadingHelper.Thread(() =>
				{
					try
					{
						using (var email = CreateClient())
						{
							while (true)
							{
								Tuple<string, string> m;

								if (!_queue.TryDequeue(out m))
									break;

								email.Send(From, To, m.Item1, m.Item2);
							}
						}

						lock (_queue.SyncRoot)
							_isThreadStarted = false;
					}
					catch (Exception ex)
					{
						Trace.WriteLine(ex);
					}
				}).Name("Email log queue").Launch();
			}
		}
			protected override void OnWriteMessage(LogMessage message)
			{
				if (ErrorEmailSent)
					return;

				if (message.Level != LogLevels.Error)
					return;

				ErrorCount++;

				var maxCount = _parent._entityRegistry.Settings.EmailErrorCount;

				if (maxCount <= 0 || ErrorCount <= maxCount)
					return;

				To = _parent._entityRegistry.Settings.EmailErrorAddress;

				if (To.IsEmpty())
					return;

				ErrorEmailSent = true;
				base.OnWriteMessage(new LogMessage(_parent._logManager.Application, TimeHelper.Now, LogLevels.Error, LocalizedStrings.Str2940Params.Put(maxCount)));
			}
示例#6
0
		/// <summary>
		/// To record a message.
		/// </summary>
		/// <param name="message">A debug message.</param>
		protected virtual void OnWriteMessage(LogMessage message)
		{
			throw new NotSupportedException(LocalizedStrings.Str17);
		}
示例#7
0
		protected override void RaiseLog(LogMessage message)
		{
			if (message.Source == this && Strategy != null)
				return;

			base.RaiseLog(message);
		}
示例#8
0
		private void OnLog(LogMessage message)
		{
			if(message.Source == Strategy)
				RaiseLog(message);
		}
示例#9
0
		private void OnLog(LogMessage message)
		{
			if (message.Level > LogLevels.Debug)
			{
				Logger.InfoFormat("[{0}] {1}", message.Source, message.Message);
			}
		}
示例#10
0
			protected override string GetSubject(LogMessage message)
			{
				return message.Source.Name;
			}
示例#11
0
		//private string DateTimeFormat
		//{
		//    get { return SeparateByDates != SeparateByDateModes.None ? TimeFormat : DateFormat + " " + TimeFormat; }
		//}

		private void WriteMessage(TextWriter writer, LogMessage message)
		{
			writer.Write(ToFastDateCharArray(message.Time));
			writer.Write("|");
			writer.Write("{0, -7}".Put(message.Level == LogLevels.Info ? string.Empty : message.Level.ToString()));
			writer.Write("|");
			writer.Write("{0, -10}".Put(message.Source.Name));
			writer.Write("|");

			if (WriteSourceId)
			{
				writer.Write("{0, -20}".Put(message.Source.Id));
				writer.Write("|");
			}

			writer.WriteLine(message.Message);
		}
示例#12
0
		/// <summary>
		/// To record a message.
		/// </summary>
		/// <param name="message">A debug message.</param>
		protected override void OnWriteMessage(LogMessage message)
		{
			if (message.IsDispose)
			{
				Dispose();
				return;
			}

			var str = "{0} | {1,-15} | {2}".Put(message.Time.ToString(LogListener.TimeFormat), message.Source, message.Message);

			switch (message.Level)
			{
				case LogLevels.Info:
					_log.Info(str);
					break;
				case LogLevels.Warning:
					_log.Warn(str);
					break;
				case LogLevels.Error:
					_log.Error(str);
					break;
				case LogLevels.Debug:
					_log.Debug(str);
					break;
				default:
					throw new ArgumentOutOfRangeException(nameof(message));
			}
		}
示例#13
0
		/// <summary>
		/// To record a message.
		/// </summary>
		/// <param name="message">A debug message.</param>
		protected override void OnWriteMessage(LogMessage message)
		{
			EnqueueMessage(message);
		}
		void ILogReceiver.AddLog(LogMessage message)
		{
			_innerAdapter.AddLog(message);
		}
示例#15
0
		/// <summary>
		/// Вызвать событие <see cref="ILogSource.Log"/>.
		/// </summary>
		/// <param name="message">Отладочное сообщение.</param>
		protected virtual void RaiseLog(LogMessage message)
		{
			if (message == null)
				throw new ArgumentNullException("message");

			if (message.Level < message.Source.LogLevel)
				return;

			//if (_log == null && Parent.IsNull())
			//	throw new InvalidOperationException("Родитель не подписан на дочерний лог.");

			_log.SafeInvoke(message);

			var parent = Parent as ILogReceiver;

			if (parent != null)
				parent.AddLog(message);
		}
示例#16
0
		private void OnLog(LogMessage message)
		{
			// если стратегия вывела не просто сообщение, то вывести на экран.
			if (message.Level != LogLevels.Info && message.Level != LogLevels.Debug)
				this.GuiAsync(() => MessageBox.Show(this, message.Message));
		}