Ejemplo n.º 1
0
        public static void Write(Exception?ex)
        {
            if (ex == null)
            {
                return;
            }

            StringBuilder builder = new StringBuilder();

            while (ex != null)
            {
                builder.Append(ex.GetType());
                builder.Append(" - ");
                builder.AppendLine(ex.Message);
                builder.AppendLine(ex.StackTrace);
                builder.AppendLine();

                ex = ex.InnerException;
            }

            Console.ForegroundColor = ConsoleColor.Red;
            Console.WriteLine(builder.ToString());
            Console.ForegroundColor = ConsoleColor.White;

            ExceptionLogged?.Invoke(builder.ToString());
        }
Ejemplo n.º 2
0
        public void LogException(string errorThrower = null, Exception exception = null)
        {
            if (_internalOutput.HasFlag(Output.Console))
            {
                if (errorThrower != null)
                {
                    Console.WriteLine(errorThrower);
                }
                if (exception != null)
                {
                    Console.WriteLine($@"Exception Thrown: {exception}");
                }
            }

            if (_internalOutput.HasFlag(Output.MessageBox))
            {
                var mbMessage = "";

                if (exception != null)
                {
                    mbMessage += $@"Exception Thrown: {exception}";
                }


                if (errorThrower != null)
                {
                    MessageBox.Show(mbMessage, errorThrower);
                }
                else
                {
                    MessageBox.Show(mbMessage);
                }
            }

            if (_internalOutput.HasFlag(Output.FileLog))
            {
                //throw new NotImplementedException();
            }

            if (_internalOutput.HasFlag(Output.Event))
            {
                ExceptionLogged?.Invoke(errorThrower, exception);
            }
        }
Ejemplo n.º 3
0
        public static void LogException(Exception ex)
        {
            ExceptionLogged?.Invoke(ex);

            // Getting exception Data
            Dictionary <string, string?> properties  = new();
            List <ErrorAttachmentLog>    attachments = new();

            foreach (DictionaryEntry de in ex.Data)
            {
                if (de.Value is ErrorAttachmentLog attachment)
                {
                    attachments.Add(attachment);
                    continue;
                }
                properties.Add(de.Key.ToString() !, de.Value?.ToString());
            }
            if (ex.InnerException != null)
            {
                attachments.Add(ErrorAttachmentLog.AttachmentWithText(ex.InnerException.ToString(), "InnerException.txt"));
            }

            // Special cases for certain exception types
            if (ex is WebException webEx)
            {
                if (Connectivity.NetworkAccess == NetworkAccess.None)
                {
                    // No Internet caused WebException, nothing to log here
                    return;
                }

                // WebException happens for external reasons, and shouldn't be treated as an exception.
                // But just in case it is logged as Event

                if (webEx.Status != 0 && webEx.Status != WebExceptionStatus.UnknownError)
                {
                    properties.Add("Status", webEx.Status.ToString());
                }
                if (webEx.InnerException != null)
                {
                    properties.Add("InnerException", webEx.InnerException.GetType().FullName);
                }
                properties.Add("Message", ex.Message);

                Analytics.TrackEvent("WebException", properties);
                return;
            }
            else if (ex is CistException cistEx)
            {
                // CistException happens for external reasons, and shouldn't be treated as an exception

                if (!properties.ContainsKey("Status"))
                {
                    properties.Add("Status", cistEx.Status.ToString());
                }

                Analytics.TrackEvent("CistException", properties);
                return;
            }
            else if (ex is MoodleException moodleEx)
            {
                // MoodleException happens for external reasons, and shouldn't be treated as an exception

                properties.Add("ErrorCode", moodleEx.ErrorCode);
                properties.Add("Message", moodleEx.Message);

                Analytics.TrackEvent("MoodleException", properties);
                return;
            }
            else if (ex is IOException && ex.Message.StartsWith("Disk full."))
            {
                return;
            }

            // Logging exception
            Crashes.TrackError(ex, properties, attachments.ToArray());
        }
Ejemplo n.º 4
0
 protected virtual void OnExceptionLogged(ExceptionLoggedEventArgs e)
 {
     ExceptionLogged?.Invoke(this, e);
 }
 static public void OnExceptionLogged(Exception ex)
 {
     ExceptionLogged?.Invoke(ex);
 }