/// <summary> /// Writes the specified <see cref="LogMessage"/> to the bus. /// </summary> /// <param name="message"></param> protected override void Write(LogMessage message) { message.Prefix = "Guest " + EngineCore.ProcessId; #if !SYNCLOG lock (_syncRoot) _queue.Enqueue(message); #else try { #if DEBUG if (System.Diagnostics.Debugger.IsAttached) { System.Diagnostics.Debug.WriteLine(FormatLogMessage(message)); return; } #endif using (EngineCore.Engine.GetEngineProcessingSpace()) _serverReporter.ReportMessage(message); } catch { } #endif }
/// <summary> /// Verifies if the specified <paramref name="logMessage"/> should be logged, /// and if so, writes the message to the log. /// </summary> /// <remarks> /// <paramref name="logMessage"/> is written to the log by calling <see cref="Write(LogMessage)"/>. /// </remarks> /// <param name="logMessage"></param> public virtual void Log(LogMessage logMessage) { if (logMessage.Level <= _level) Write(logMessage); }
/// <summary> /// Formats the given <see cref="LogMessage"/> to a string. /// </summary> /// <param name="message">The <see cref="LogMessage"/> to format to a <see cref="string"/>.</param> /// <returns></returns> protected virtual string FormatLogMessage(LogMessage message) { var formattedMessage = string.Format("{0} [{1}]{2} [{3}] {4}", message.DateTime.ToString("yyyy-MM-dd HH:mm:ss.ffffff"), message.Level, message.Prefix != null ? " [" + message.Prefix + "]" : "", message.SendingThread, message.Message) + (message.Exception != null ? "\r\n" + message.Exception.ToFormattedString(MustIncludeStackTrace(message.Level)) : ""); return formattedMessage; }
/// <summary> /// Formats the specified <see cref="LogMessage"/> to a <see cref="string"/> using <see cref="FormatLogMessage"/>. /// The message is then passed to <see cref="Write(string)"/> using a thread from <see cref="ThreadPool"/>. /// </summary> /// <param name="message"></param> protected virtual void Write(LogMessage message) { // Note: When guest sends a batch of messages, this method consumes all ThreadPool threads ThreadPool.QueueUserWorkItem(CallWriteForString, FormatLogMessage(message)); }
public void ReportMessage(LogMessage message) { HostCore.Log.Log(message); }