/// <summary>
 /// Called when an exception has been logged to allow the app to modify the display
 /// and/or terminate.
 /// </summary>
 /// <param name="ea"></param>
 protected virtual void OnMessageLogged(MessageLoggedEventArgs ea)
 {
     if (MessageLogged != null)
     {
         MessageLogged(this, ea);
     }
 }
示例#2
0
        void mdf_LogMessage(object sender, MessageLoggedEventArgs e)
        {
            try
            {
                var currentT = Thread.CurrentThread.ManagedThreadId;

                if (threadIds.ContainsKey(currentT))
                {
                    currentT = threadIds[currentT];
                }
                else
                {
                    lock (threadIds)
                    {
                        threadIds.Add(currentT, threadIds.Count);
                        currentT = threadIds.Count - 1;
                    }
                }
                if (this.InvokeRequired)
                {
                    this.Invoke((Action) delegate()
                    {
                        int iout;
                        tLabels[currentT].Text = e.Message;
                    });
                }
                AddToLog(e.Message);
            }
            catch (Exception ee)
            {
                System.Diagnostics.Trace.WriteLine(ee.Message);
            }
        }
示例#3
0
            public void Log(object sender, MessageLoggedEventArgs e)
            {
                MessageLogged?.Invoke(sender, e);

                var level = e.Severity switch
                {
                    LogMessageSeverity.Trace => LogLevel.Trace,
                    LogMessageSeverity.Debug => LogLevel.Debug,
                    LogMessageSeverity.Information => LogLevel.Information,
                    LogMessageSeverity.Warning => LogLevel.Warning,
                    LogMessageSeverity.Error => LogLevel.Error,
                    LogMessageSeverity.Critical => LogLevel.Critical,

                    _ => LogLevel.None
                };

                // downgrade unknown dispatch logs to debug level
                if (e.Source.Equals("Gateway", StringComparison.OrdinalIgnoreCase) && e.Message.Contains("Unknown dispatch", StringComparison.OrdinalIgnoreCase))
                {
                    level = level < LogLevel.Debug ? level : LogLevel.Debug;
                }

                _logger.Log(level, e.Exception, $"[{e.Source}] {e.Message}");
            }
        }
示例#4
0
 /// <summary>
 /// Log a message
 /// </summary>
 /// <param name="sender">
 /// The sender.
 /// </param>
 /// <param name="e">
 /// The MessageLoggedEventArgs.
 /// </param>
 private void HandBrakeInstanceMessageLogged(object sender, MessageLoggedEventArgs e)
 {
     lock (LogLock)
     {
         this.logging.AppendLine(e.Message);
     }
 }
示例#5
0
        void Log_MessageLogged(object sender, MessageLoggedEventArgs e)
        {
            var message = e.Message;

            var serializableMessage = message as SerializableLogMessage;

            if (serializableMessage == null)
            {
                var logMessage = message as LogMessage;
                if (logMessage != null)
                {
                    // Ignore MicroThreadCancelledException (they are supposed to be intentionally triggered by live scripting reloading)
                    if (logMessage.Exception is MicroThreadCancelledException)
                    {
                        return;
                    }

                    serializableMessage = new SerializableLogMessage(logMessage);
                }
            }

            if (serializableMessage == null)
            {
                throw new InvalidOperationException(@"Unable to process the given log message.");
            }

            host.OnLogMessage(serializableMessage);
        }
示例#6
0
            public void Log(object sender, MessageLoggedEventArgs e)
            {
                MessageLogged?.Invoke(sender, e);

                var level = e.Severity switch
                {
                    LogMessageSeverity.Trace => LogLevel.Trace,
                    LogMessageSeverity.Debug => LogLevel.Debug,
                    LogMessageSeverity.Information => LogLevel.Information,
                    LogMessageSeverity.Warning => LogLevel.Warning,
                    LogMessageSeverity.Error => LogLevel.Error,
                    LogMessageSeverity.Critical => LogLevel.Critical,

                    _ => LogLevel.None
                };

                // downgrade unknown dispatch logs to debug level
                if (e.Source.Equals("Gateway", StringComparison.OrdinalIgnoreCase) && e.Message.Contains("Unknown dispatch", StringComparison.OrdinalIgnoreCase))
                {
                    level = level < LogLevel.Debug ? level : LogLevel.Debug;
                }

                _logger.Log(level, e.Exception, $"[{e.Source}] {e.Message}");

                // log a note about expired tokens: https://github.com/chiyadev/MudaeFarm/issues/153
                if (e.Message.Contains("AuthenticationFailed", StringComparison.OrdinalIgnoreCase))
                {
                    _logger.Log(level, "Your Discord authentication token seems to have expired. Please try updating your token in \"profiles.json\" file in the folder \"%localappdata%\\MudaeFarm\".");
                }
            }
        }
示例#7
0
 /// <summary>
 /// Log a message
 /// </summary>
 /// <param name="sender">
 /// The sender.
 /// </param>
 /// <param name="e">
 /// The MessageLoggedEventArgs.
 /// </param>
 private void HandBrakeInstanceMessageLogged(object sender, MessageLoggedEventArgs e)
 {
     lock (LogLock)
     {
         this.ProcessLogMessage(e.Message);
     }
 }
示例#8
0
        private void HandBrakeUtils_MessageLogged(object sender, MessageLoggedEventArgs e)
        {
            if (e == null || string.IsNullOrEmpty(e.Message))
            {
                return;
            }

            this.LogMessage(e.Message, LogMessageType.ScanOrEncode, LogLevel.Info);
        }
示例#9
0
        private void HandBrakeUtils_MessageLogged(object sender, MessageLoggedEventArgs e)
        {
            if (e == null || string.IsNullOrEmpty(e.Message))
            {
                return;
            }

            this.LogMessage(e.Message);
        }
示例#10
0
        private static void HandBrakeUtils_MessageLogged(object sender, MessageLoggedEventArgs e)
        {
            if (e == null || string.IsNullOrEmpty(e.Message))
            {
                return;
            }

            generalAppLogger?.LogMessage(e.Message);
        }
示例#11
0
文件: UI.cs 项目: radtek/tstunnels
 public void Server_MessageLogged(object sender, MessageLoggedEventArgs e)
 {
     if (InvokeRequired)
     {
         Invoke(new EventHandler <MessageLoggedEventArgs>(Server_MessageLogged), new[] { sender, e });
         return;
     }
     AppendLogMessage(e.Message);
 }
示例#12
0
 /// <summary>
 /// Log a message
 /// </summary>
 /// <param name="sender">
 /// The sender.
 /// </param>
 /// <param name="e">
 /// The MessageLoggedEventArgs.
 /// </param>
 private void HandBrakeInstanceErrorLogged(object sender, MessageLoggedEventArgs e)
 {
     if (this.loggingEnabled)
     {
         lock (LogLock)
         {
             this.ProcessLogMessage(e.Message);
         }
     }
 }
示例#13
0
 void mdf_Alert(object sender, MessageLoggedEventArgs e)
 {
     if (this.InvokeRequired)
     {
         this.Invoke((Action) delegate()
         {
             ntfMonitor.ShowBalloonTip(4000, e.Title, e.Message, ToolTipIcon.Info);
         });
     }
 }
示例#14
0
        private void OnErrorLoggedLocal(object sender, MessageLoggedEventArgs e)
        {
            var entry = new LogEntry
            {
                LogType = LogType.Error,
                Source  = LogSource.HandBrake,
                Text    = "ERROR: " + e.Message
            };

            this.AddEntry(entry);
        }
示例#15
0
        private void OnErrorLogged(object sender, MessageLoggedEventArgs e)
        {
            var entry = new LogEntry
            {
                LogType = LogType.Error,
                Source  = LogSource.HandBrake,
                Text    = "ERROR: " + e.Message
            };

            // Parent will also get this message
            this.AddEntry(entry, logParent: false);
        }
示例#16
0
 /// <summary>
 /// The callback of the <see cref="Logger.MessageLogged"/> event, used to monitor incoming messages.
 /// </summary>
 /// <param name="sender">The event sender.</param>
 /// <param name="args">The event argument.</param>
 private void MessageLogged(object sender, [NotNull] MessageLoggedEventArgs args)
 {
     lock (pendingMessages)
     {
         pendingMessages.Add(Tuple.Create((Logger)sender, args.Message));
         if (!updatePending)
         {
             updatePending = true;
             Dispatcher.InvokeAsync(UpdateMessages);
         }
     }
 }
示例#17
0
        /// <summary>
        /// Log a message
        /// </summary>
        /// <param name="sender">
        /// The sender.
        /// </param>
        /// <param name="e">
        /// The MessageLoggedEventArgs.
        /// </param>
        private void HandBrakeInstanceMessageLogged(object sender, MessageLoggedEventArgs e)
        {
            lock (LogLock)
            {
                if (this.scanLog != null)
                {
                    this.scanLog.WriteLine(e.Message);
                }

                this.logging.AppendLine(e.Message);
            }
        }
示例#18
0
        private Task LogAsync(MessageLoggedEventArgs args)
        {
            var logEventLevel = args.Severity switch
            {
                LogMessageSeverity.Trace => LogEventLevel.Verbose,
                LogMessageSeverity.Information => LogEventLevel.Information,
                LogMessageSeverity.Debug => LogEventLevel.Debug,
                LogMessageSeverity.Warning => LogEventLevel.Warning,
                LogMessageSeverity.Error => LogEventLevel.Error,
                LogMessageSeverity.Critical => LogEventLevel.Fatal,
                _ => LogEventLevel.Verbose
            };

            Log.Logger.Write(logEventLevel, $"{args.Source}: {args.Message}");

            return(Task.CompletedTask);
        }
示例#19
0
        private void OnMessageLogged(object sender, MessageLoggedEventArgs e)
        {
            //print("DebugPanel.OnMessageLogged");

            // remove oldest messages if list is full
            int surplusMessages = messages.Count + 1 - messageBufferSize;

            if (keepErrors)
            {
                surplusMessages -= logLevelMsgCounts[Log.LevelError];
            }

            if (surplusMessages > 0 && !keepErrors)
            {
                messages.RemoveRange(0, surplusMessages);
            }
            else if (surplusMessages > 0 && keepErrors)
            {
                for (int i = 0; surplusMessages > 0 && i < messages.Count; /* nothing here */)
                {
                    if (messages[i].LogLevel == Log.LevelError)
                    {
                        i++; // keep error messages
                    }
                    else
                    {
                        messages.RemoveAt(i);
                        surplusMessages--;
                    }
                }
            }

            // update toggle labels
            logLevelMsgCounts[e.LogLevel]++;
            logLevelToggleLabels[e.LogLevel].text = string.Format("{0} ({1})", logLevelToggleCaptions[e.LogLevel], logLevelMsgCounts[e.LogLevel]);
            if (e.LogLevel == Log.LevelError || e.LogLevel == Log.LevelWarning)
            {
                logLevelToggleLabels[e.LogLevel].fontStyle = FontStyle.Bold;
            }

            // add message to list
            messages.Add(e);
            UpdateMessageView(DebugPanelEvent.MessageReceived);
        }
示例#20
0
 protected void LogToolMessage(MessageLoggedEventArgs e)
 {
     if (e.Exception != null)
     {
         Console.Error.WriteLine(e.Exception);
     }
     else if (e.IsError)
     {
         Console.Error.WriteLine(e.Message);
     }
     else if (e.IsVerbose && Program.Verbose)
     {
         Console.WriteLine(e.Message);
     }
     else if (!e.IsVerbose)
     {
         Console.WriteLine(e.Message);
     }
 }
示例#21
0
 protected void LogToolMessage(MessageLoggedEventArgs e)
 {
     if (e.Exception != null)
     {
         Log.LogErrorFromException(e.Exception);
     }
     else if (e.IsError)
     {
         Log.LogError(e.Message);
     }
     else if (e.IsVerbose)
     {
         Log.LogMessage(MessageImportance.Low, e.Message);
     }
     else
     {
         Log.LogMessage(e.Message);
     }
 }
        private void AddDetailMessage(MessageLoggedEventArgs e)
        {
            if (string.IsNullOrWhiteSpace(e.Message))
            {
                return;
            }

            Application.Current.Dispatcher.Invoke(() =>
            {
                lock (this.DetailMessages)
                {
                    while (this.DetailMessages.Count >= 100)
                    {
                        this.DetailMessages.RemoveAt(this.DetailMessages.Count - 1);
                    }

                    this.DetailMessages.Insert(0, new LoggedMessageViewModel(e));
                }
            });
        }
        /// <summary>
        /// Handles untrapped exceptions on the main Application thread. If any EventHandlers have been
        /// added they are called, otherwise a message box is shown to the user with the option to close
        /// the application.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected virtual void OnThreadException(object sender, ThreadExceptionEventArgs e)
        {
            try {
                if (ThreadException != null)
                {
                    ThreadException(sender, e);
                }
                else
                {
                    LogFile.Log(e.Exception.ToString());

                    var ea = new MessageLoggedEventArgs(Traps.Thread, e.Exception, false);
                    OnMessageLogged(ea);
                    if (ea.Terminating || (ea.DisplayMessageBox && MessageBox.Show(e.Exception.Message + "\r\n\r\nPress Cancel to Exit", "Unexpected Error", MessageBoxButtons.OKCancel, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1) == DialogResult.Cancel))
                    {
                        terminate();
                    }
                }
            } catch {
                // Can't do anything with an exception in here.
            }
        }
示例#24
0
        void Log_MessageLogged(object sender, MessageLoggedEventArgs e)
        {
            var message = e.Message;

            var serializableMessage = message as SerializableLogMessage;

            if (serializableMessage == null)
            {
                var logMessage = message as LogMessage;
                if (logMessage != null)
                {
                    serializableMessage = new SerializableLogMessage(logMessage);
                }
            }

            if (serializableMessage == null)
            {
                throw new InvalidOperationException(@"Unable to process the given log message.");
            }

            host.OnLogMessage(serializableMessage);
        }
        /// <summary>
        /// Handles untrapped exceptions on threads other than the main Application thread. If any
        /// EventHandlers have been added they are called, otherwise a message box is shown to the user.
        /// If the event can be recovered from, which is unusual, the user is given the option to close
        /// the application.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected virtual void OnGeneralException(object sender, UnhandledExceptionEventArgs e)
        {
            try {
                if (GeneralException != null)
                {
                    GeneralException(sender, e);
                }
                else
                {
                    var ex = e.ExceptionObject as Exception;
                    if (ex == null)
                    {
                        LogFile.Log("Unhandled exception with no Exception object");
                    }
                    else
                    {
                        LogFile.Log(ex.ToString());
                    }
                    var ea = new MessageLoggedEventArgs(Traps.General, ex, e.IsTerminating);
                    OnMessageLogged(ea);

                    string msg = ex == null ? "Unknown Exception" : ex.Message;
                    if (e.IsTerminating)
                    {
                        if (ea.DisplayMessageBox)
                        {
                            MessageBox.Show(msg + "\r\n\r\nThe program is terminating.", "Unexpected Error");
                        }
                    }
                    else if (ea.Terminating || (ea.DisplayMessageBox && MessageBox.Show(msg + "\r\n\r\nPress Cancel to Exit the program", "Unexpected Error", MessageBoxButtons.OKCancel, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1) == DialogResult.Cancel))
                    {
                        terminate();
                    }
                }
            } catch {
                // Can't do anything with an exception in here.
            }
        }
示例#26
0
        private void DisqordLog(object?sender, MessageLoggedEventArgs args)
        {
            var logEventLevel = args.Severity switch
            {
                LogMessageSeverity.Trace => LogEventLevel.Verbose,
                LogMessageSeverity.Information => LogEventLevel.Information,
                LogMessageSeverity.Debug => LogEventLevel.Debug,
                LogMessageSeverity.Warning => LogEventLevel.Warning,
                LogMessageSeverity.Error => LogEventLevel.Error,
                LogMessageSeverity.Critical => LogEventLevel.Fatal,
                _ => LogEventLevel.Verbose
            };

            if (args.Message != null &&
                (Regex.IsMatch(args.Message, @"Guild.*became available") ||
                 args.Message.Contains("MessageUpdated") ||
                 args.Message.Contains("Requesting offline members for")))
            {
                return;
            }

            Log.Logger.Write(logEventLevel, $"{args.Source}: {args.Exception?.ToString() ?? args.Message}");
        }
示例#27
0
        private void UpdateMessageLabels(int firstMsgIndex, int firstLblIndex, int lblCount)
        {
            //Debug.LogFormat("DebugPanel.updateMessageLabels({0}, {1}, {2})", firstMsgIndex, firstLblIndex, lblCount);

            // TO.DO if we are at the bottom (value of topMsgIndex such that the last message is shown in a visible label: fill the labels beginning with the last to avoid gaps)

            //Debug.LogFormat("updateMessageLabels(firstMsgIndex={0}, firstLblIndex={1}, lblCount={2})", firstMsgIndex, firstLblIndex, lblCount);
            int lblIndex = firstLblIndex;
            int msgIndex = firstMsgIndex;

            //Debug.LogFormat("{0} < {1} + {2} ({5}) && {3} < {4} ({6})", lblIndex, firstLblIndex, lblCount, msgIndex, messages.Count, lblIndex < firstLblIndex + lblCount, msgIndex < messages.Count);
            while (lblIndex < firstLblIndex + lblCount && msgIndex < messages.Count)
            {
                MessageLoggedEventArgs msg = messages[msgIndex];
                if (logLevelFlags[msg.LogLevel])
                {
                    //Debug.LogFormat("Updating lblIndex {0} (of {2}) with msgIndex {1} (of {3})", lblIndex, msgIndex, msgLabels.Length, messages.Count);
                    msgLabels[lblIndex].text = string.Format(msgFormat, GetColor(msg.LogLevel), msg.Timestamp, GetPrefix(msg.LogLevel), msg.Message);
                    msgLabels[lblIndex].gameObject.SetActive(true);
                    msgIndex++;
                    lblIndex++;
                }
                else
                {
                    msgIndex++;
                }
                //Debug.LogFormat("{0} < {1} + {2} ({5}) && {3} < {4} ({6})", lblIndex, firstLblIndex, lblCount, msgIndex, messages.Count, lblIndex < firstLblIndex + lblCount, msgIndex < messages.Count);
            }

            // if there are no more messages but there are more labels, make all subsequent labels invisible
            while (lblIndex < msgLabels.Length)
            {
                msgLabels[lblIndex].gameObject.SetActive(false);
                lblIndex++;
            }
        }
 private static void FireEventAppender_MessageLoggedEventHandler(object sender, MessageLoggedEventArgs e)
 {
     System.Diagnostics.Trace.WriteLine("EVENT ****" + e.LoggingEvent.RenderedMessage + "****");
 }
示例#29
0
 public LoggedMessageViewModel(MessageLoggedEventArgs e)
 {
     this.e = e;
 }
示例#30
0
 /// <summary>
 /// Log a message
 /// </summary>
 /// <param name="sender">
 /// The sender.
 /// </param>
 /// <param name="e">
 /// The MessageLoggedEventArgs.
 /// </param>
 private void HandBrakeInstanceMessageLogged(object sender, MessageLoggedEventArgs e)
 {
     if (this.loggingEnabled)
     {
         lock (logLock)
         {
             this.ProcessLogMessage(e.Message);
         }
     }
 }
示例#31
0
文件: Logger.cs 项目: Runcy/VidCoder
		private void OnErrorLogged(object sender, MessageLoggedEventArgs e)
		{
			var entry = new LogEntry
			{
				LogType = LogType.Error,
				Source = LogSource.HandBrake,
				Text = "ERROR: " + e.Message
			};

			// Parent will also get this message
			this.AddEntry(entry, logParent: false);
		}
示例#32
0
        /// <summary>
        /// Log a message
        /// </summary>
        /// <param name="sender">
        /// The sender.
        /// </param>
        /// <param name="e">
        /// The MessageLoggedEventArgs.
        /// </param>
        private void HandBrakeInstanceMessageLogged(object sender, MessageLoggedEventArgs e)
        {
            lock (LogLock)
            {
                if (this.scanLog != null)
                {
                    this.scanLog.WriteLine(e.Message);
                }

                this.logging.AppendLine(e.Message);
            }
        }
 /// <summary>
 /// Log a message
 /// </summary>
 /// <param name="sender">
 /// The sender.
 /// </param>
 /// <param name="e">
 /// The MessageLoggedEventArgs.
 /// </param>
 private void HandBrakeInstanceMessageLogged(object sender, MessageLoggedEventArgs e)
 {
     lock (LogLock)
     {
         this.logging.AppendLine(e.Message);
     }
 }
示例#34
0
 private void OnMessageLogged(object sender, MessageLoggedEventArgs e)
 {
     _logger.Log(e.Severity.ToString(), e.Message, e.Exception);
 }