Example #1
0
        public static void LogEvent(object exceptionObject, string msg = null, bool includeReporting = false)
        {
            // log event/exception
            try
            {
                var logPath = Util.GetAppDataFolder("logs") + "\\service.exceptions.log";
                if (msg != null)
                {
                    System.IO.File.AppendAllText(logPath, "\r\n[" + DateTime.Now + "] :: " + msg);
                }

                if (exceptionObject != null)
                {
                    System.IO.File.AppendAllText(logPath, "\r\nService Exception :: [" + DateTime.Now + "] :: " + ((Exception)exceptionObject).ToString());
                }
            }
            catch { }

            //submit diagnostic info if connection available and status reporting enabled
            if (Management.CoreAppSettings.Current.EnableStatusReporting && includeReporting)
            {
                try
                {
                    if (exceptionObject != null && exceptionObject is Exception)
                    {
                        var tc         = new Certify.Management.Util().InitTelemetry();
                        var properties = new Dictionary <string, string>
                        {
                            { "AppVersion", Management.Util.GetAppVersion().ToString() }
                        };

                        tc.TrackException((Exception)exceptionObject, properties);
                        tc.Flush();
                    }
                }
                catch { }

                var client = new HttpClient();

                var appVersion = Management.Util.GetAppVersion();

                var jsonRequest = Newtonsoft.Json.JsonConvert.SerializeObject(
                    new Models.Shared.FeedbackReport
                {
                    EmailAddress   = "(service exception)",
                    Comment        = "An unhandled service exception has occurred.: " + ((Exception)exceptionObject)?.ToString(),
                    IsException    = true,
                    AppVersion     = appVersion.ToString(),
                    SupportingData = new
                    {
                        Framework   = Certify.Management.Util.GetDotNetVersion(),
                        OS          = Environment.OSVersion.ToString(),
                        AppVersion  = Management.Util.GetAppVersion(),
                        IsException = true
                    }
                });

                var data = new StringContent(jsonRequest, System.Text.Encoding.UTF8, "application/json");
                try
                {
                    Task.Run(async() =>
                    {
                        await client.PostAsync(Models.API.Config.APIBaseURI + "feedback/submit", data);
                    });
                }
                catch (Exception exp)
                {
                    System.Diagnostics.Debug.WriteLine(exp.ToString());
                }
            }
        }