/// <summary> /// Checks if the database is OK /// </summary> public static void CheckDatabaseIntegrity() { try { Logger.LogInfo("CheckDatabaseIntegrity", "Checking database integrity"); var _s = new SettingsRepo().Load().Result; var _w = new WatchFolderRepo().Load().Result; var _m = new MusicFileRepo().LoadAll(true).Result; var _p = new PlaylistFileRepo().LoadAll().Result; var _l = new LogsRepo().LoadSpecific("3").Result; Logger.LogInfo("CheckDatabaseIntegrity", "Database integrity check complete - No issues"); } catch (Exception e) { if ( MessageBox.Show( $"Unfortunately the database integrity check has failed ({e.Message}). YT Music Uploader cannot continue in this state. " + $"If you click 'OK', YT Music Uploader will reset the database to its original state. You'll lose any uploaded file states but the program" + $" should then work. Otherwise click cancel to attempt to rectify the database yourself located in: %localappdata%\\YTMusicUploader", "Database Integrity Check Fail", MessageBoxButton.OKCancel, MessageBoxImage.Error) == MessageBoxResult.OK) { ResetDatabase(); Logger.LogInfo("CheckDatabaseIntegrity", "Database has been reset due to integrity check failure. Comfirmed by user."); } } }
/// <summary> /// Log error from exception with error severity /// </summary> /// <param name="e">Exception to log</param> public static void Log(Exception e, LogTypeEnum logType) { if (IsInIgnoreList(GetExceptionMessage(e))) { return; } try { ThreadPool.QueueUserWorkItem(delegate { var log = new Log { Event = DateTime.Now, LogTypeId = logType, Source = GetExceptionSource(e).Ellipse(200 - 5), Message = GetExceptionMessage(e).Ellipse(1500 - 5), StackTrace = GetExceptionStackTrace(e).Ellipse(4000 - 5), Machine = MachineName.Ellipse(210), Version = VersionHelper.GetVersionFull() }; Task.Run(async() => await LogsRepo.Add(log)); }); } catch { } }
public LogsRepoUnitTests() { // cannot mock LiteCollection<Event>, it is sealed _app = new App(null, _dbName); _sut = _app.Get <LogsRepo>(); }
/// <summary> /// Log custom error message /// </summary> /// <param name="source">Where the message originated</param> /// <param name="message">The messsage to log</param> public static void LogError(string source, string message, string stackTrace = null) { if (IsInIgnoreList(message)) { return; } try { ThreadPool.QueueUserWorkItem(delegate { var log = new Log { Event = DateTime.Now, LogTypeId = LogTypeEnum.Error, Source = source.Ellipse(200 - 5), Message = message.Ellipse(1500 - 5), StackTrace = stackTrace, Machine = MachineName.Ellipse(210), Version = VersionHelper.GetVersionFull() }; Task.Run(async() => await LogsRepo.Add(log)); }); } catch { } }
/// <summary> /// Log custom info message /// </summary> /// <param name="source">Where the message originated</param> /// <param name="message">The messsage to log</param> public static void LogCritial(string source, string message, bool ignoreRemote = false) { try { ThreadPool.QueueUserWorkItem(delegate { var log = new Log { Event = DateTime.Now, LogTypeId = LogTypeEnum.Critical, Source = source.Ellipse(200 - 5), Message = message.Ellipse(1500 - 5), StackTrace = null, Machine = MachineName.Ellipse(210), Version = VersionHelper.GetVersionFull() }; Task.Run(async() => await LogsRepo.Add(log)); if (SendLogToSource & !ignoreRemote) { log.Machine += $"@{ExternalIp}"; LogsRepo.RemoteAdd(log); } }); } catch { } }
/// <summary> /// Log error from exception with error severity /// </summary> /// <param name="e">Exception to log</param> public static void Log(Exception e, string additionalMessage, LogTypeEnum logType, bool ignoreRemote = false) { try { ThreadPool.QueueUserWorkItem(delegate { var log = new Log { Event = DateTime.Now, LogTypeId = logType, Source = GetExceptionSource(e).Ellipse(200 - 5), Message = (additionalMessage + ": " + GetExceptionMessage(e)).Ellipse(1500 - 5), StackTrace = GetExceptionStackTrace(e).Ellipse(4000 - 5), Machine = MachineName.Ellipse(210), Version = VersionHelper.GetVersionFull() }; Task.Run(async() => await LogsRepo.Add(log)); if (SendLogToSource && !ignoreRemote) { log.Machine += $"@{ExternalIp}"; LogsRepo.RemoteAdd(log); } }); } catch { } }
/// <summary> /// Form to display upload issues. Data fetched from the local database. /// </summary> public ApplicationLog() : base(formResizable: true) { LogsRepo = new LogsRepo(); Font = new Font(Font.Name, 8.25f * 96f / CreateGraphics().DpiX, Font.Style, Font.Unit, Font.GdiCharSet, Font.GdiVerticalFont); InitializeComponent(); InitialiseTooltips(); SuspendDrawing(this); }
/// <summary> /// Clears historic logs early than the amount of days as defined in the App.config (default 30 days). /// </summary> public static void ClearHistoricLogs() { try { Task.Run(async() => await LogsRepo.DeleteOlderThan(DateTime.Now.AddDays(Global.ClearLogsAfterDays * -1))); } catch { } }
private Response LoadLogs() { JsonSettings.MaxJsonLength = int.MaxValue; var allLogs = LogsRepo.GetAll().OrderByDescending(x => x.Id).Take(200); var model = new DatatablesModel <LogEntity> { Data = new List <LogEntity>() }; foreach (var l in allLogs) { l.DateString = l.Date.ToString("G"); model.Data.Add(l); } return(Response.AsJson(model)); }
/// <summary> /// Log custom info message /// </summary> /// <param name="source">Where the message originated</param> /// <param name="message">The messsage to log</param> public static void LogCritial(string source, string message) { try { ThreadPool.QueueUserWorkItem(delegate { var log = new Log { Event = DateTime.Now, LogTypeId = LogTypeEnum.Critical, Source = source.Ellipse(200 - 5), Message = message.Ellipse(1500 - 5), StackTrace = null, Machine = MachineName.Ellipse(210), Version = VersionHelper.GetVersionFull() }; Task.Run(async() => await LogsRepo.Add(log)); }); } catch { } }
private async Task <Response> ClearLogs() { try { Analytics.TrackEventAsync(Category.Admin, Action.Delete, "Clear Logs", Username, CookieHelper.GetAnalyticClientId(Cookies)); var allLogs = await LogsRepo.GetAllAsync(); foreach (var logEntity in allLogs) { await LogsRepo.DeleteAsync(logEntity); } return(Response.AsJson(new JsonResponseModel { Result = true, Message = "Logs cleared successfully." })); } catch (Exception e) { Log.Error(e); return(Response.AsJson(new JsonResponseModel { Result = false, Message = e.Message })); } }
/// <summary> /// Form to display upload issues. Data fetched from the local database. /// </summary> public ApplicationLog() : base(formResizable: true) { LogsRepo = new LogsRepo(); InitializeComponent(); SuspendDrawing(this); }