private static async Task SaveWebErrorLog(WebErrorLog webErrorLog) { if (!await SendToServer(webErrorLog)) { SaveToFile(webErrorLog, _fileSavePath); } }
public static void AddHandler(string version, ENSource source, string path, string hardSerial, string username = "******", string password = "******", int minutes = 10, int minSecendsBetweenExeptions = 30) { if (minSecendsBetweenExeptions <= 60) { WebErrorLog.MinMinutsBetweenExeptions = 1; } else { WebErrorLog.MinMinutsBetweenExeptions = minSecendsBetweenExeptions / 60; } Username = username; Password = password; if (inited) { return; } inited = true; if (string.IsNullOrEmpty(version)) { new ArgumentNullException(nameof(version), "The version can not be null or empty"); } if (path == null) { new ArgumentNullException(nameof(path), "The path can not be null"); } if (string.IsNullOrEmpty(username)) { new ArgumentNullException(nameof(username), "The username can not be null or empty"); } if (string.IsNullOrEmpty(password)) { new ArgumentNullException(nameof(password), "The password can not be null or empty"); } WebErrorLog.SetMinute(minutes); AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(WebErrorLog.ErrorInstence.UnhandledExceptionLog); Source = source; TakeScreenShot = false; Path = path; Version = version; Username = username; Password = password; HardSerial = hardSerial; if (_retryThread == null) { _retryThread = Task.Run(async() => { await retrySend(); }); } }
private static async Task <bool> SendToServer(WebErrorLog cls) { try { using (var client = new HttpClient()) { var json = Json.ToStringJson(cls); var content = new StringContent(json, Encoding.UTF8, "application/json"); var result = await client.PostAsync(Utilities.WebApi + "/api/ErrorHandler/SaveAsync", content); } return(true); } catch (Exception) { return(false); } }
private static void SaveToFile(WebErrorLog webErrorLog, string localSavePath) { try { if (localSavePath?.Length < 1) { return; } if (!Directory.Exists(localSavePath)) { Directory.CreateDirectory(localSavePath); } var filepath = System.IO.Path.Combine(localSavePath, webErrorLog.Guid + ".txt"); File.WriteAllText(filepath, JsonConvert.SerializeObject(webErrorLog)); } catch { } }
public static async Task OnExceptionHandle(WebErrorLog e) { try { var fileSplited = e.ClassName.Split(@"/\".ToCharArray()); e.ClassName = fileSplited[fileSplited.Length - 1]; e.Source = Source; e.Version = Version; e.Path = Path; e.HardSerial = HardSerial; if (AndroidIme > 0) { e.AndroidIme = AndroidIme.ToString(); } await SaveWebErrorLog(e); } catch (Exception ex) { WebErrorLog.ErrorInstence.StartErrorLog(ex); } }