Beispiel #1
0
        /// <summary>
        /// Logs messages to the log file
        /// </summary>
        /// <param name="msg"></param>
        public static void Log(string msg, Exception ex = null)
        {
            string exMsg = string.Empty;

            if (ex != null)
            {
                var version    = mmApp.GetVersion();
                var winVersion = ComputerInfo.GetWindowsVersion() +
                                 " - " + CultureInfo.CurrentUICulture.IetfLanguageTag +
                                 " - NET " + ComputerInfo.GetDotnetVersion() + " - " +
                                 (Environment.Is64BitProcess ? "64 bit" : "32 bit");

                ex    = ex.GetBaseException();
                exMsg = $@"
Markdown Monster v{version}
{winVersion}
---
{ex.Source}
{ex.StackTrace}
---------------------------


";
                SendBugReport(ex, msg);
            }

            var text = msg + exMsg;

            StringUtils.LogString(text, Path.Combine(Configuration.CommonFolder,
                                                     "MarkdownMonsterErrors.txt"), Encoding.UTF8);
        }
Beispiel #2
0
        public static void SendBugReport(Exception ex, string msg = null)
        {
            var bug = new BugReport()
            {
                TimeStamp  = DateTime.UtcNow,
                Message    = ex.Message,
                Product    = "Markdown Monster",
                Version    = mmApp.GetVersion(),
                WinVersion = ComputerInfo.GetWindowsVersion() +
                             " - " + CultureInfo.CurrentUICulture.IetfLanguageTag +
                             " - .NET " + ComputerInfo.GetDotnetVersion() + " - " +
                             (Environment.Is64BitProcess ? "64 bit" : "32 bit"),
                StackTrace = (ex.Source + "\r\n\r\n" + ex.StackTrace).Trim()
            };

            if (!string.IsNullOrEmpty(msg))
            {
                bug.Message = msg + "\r\n" + bug.Message;
            }

            new TaskFactory().StartNew(
                (bg) =>
            {
                try
                {
                    var temp = HttpUtils.JsonRequest <BugReport>(new HttpRequestSettings()
                    {
                        Url      = mmApp.Configuration.BugReportUrl,
                        HttpVerb = "POST",
                        Content  = bg,
                        Timeout  = 3000
                    });
                }
                catch (Exception ex2)
                {
                    // don't log with exception otherwise we get an endless loop
                    Log("Unable to report bug: " + ex2.Message);
                }
            }, bug);
        }
Beispiel #3
0
        /// <summary>
        /// Logs messages to the log file
        /// </summary>
        /// <param name="msg"></param>
        public static void Log(string msg, Exception ex = null, bool unhandledException = false)
        {
            string version    = GetVersion();
            string winVersion = null;

            string exMsg = string.Empty;

            if (ex != null)
            {
                winVersion = ComputerInfo.GetWindowsVersion() +
                             " - " + CultureInfo.CurrentUICulture.IetfLanguageTag +
                             " - NET " + ComputerInfo.GetDotnetVersion() + " - " +
                             (Environment.Is64BitProcess ? "64 bit" : "32 bit");

                ex    = ex.GetBaseException();
                exMsg = $@"
Markdown Monster v{version}
{winVersion}
---
{ex.Source}
{ex.StackTrace}
---------------------------


";
                SendBugReport(ex, msg);
            }

            if (Telemetry.UseApplicationInsights)
            {
                if (ex != null)
                {
                    AppRunTelemetry.Telemetry.Success = false;
                    AppInsights.TrackException(ex,
                                               new Dictionary <string, string>
                    {
                        { "msg", msg },
                        { "exmsg", ex.Message },
                        { "exsource", ex.Source },
                        { "extrace", ex.StackTrace },
                        { "severity", unhandledException ? "unhandled" : "" },
                        { "version", version },
                        { "winversion", winVersion },
                        { "usage", Configuration.ApplicationUpdates.AccessCount.ToString() },
                        { "registered", UnlockKey.IsRegistered().ToString() }
                    });
                }
                else
                {
                    var props = new Dictionary <string, string>()
                    {
                        { "msg", msg },
                        { "version", GetVersion() },
                        { "usage", Configuration.ApplicationUpdates.AccessCount.ToString() },
                        { "registered", UnlockKey.IsRegistered().ToString() }
                    };
                    AppInsights.TrackTrace(msg, props);
                }
            }
            var text = msg + exMsg;

            LogToLogfile(text);
        }