internal void AddBackgroundInformation(string task, string statusInfo) { Logger.Debug(task + "\n" + statusInfo); if (BackupService.BusyWithBackups == true) { return; } lock (Locker) { var item = new BackgroundInformation(task, statusInfo); using (var session = DataService.OpenSession()) { session.Save(item); session.Flush(); } } }
internal void AddBackgroundError(string action, Exception error, bool logInDatabase = true) { if (BackupService.BusyWithBackups == true) { return; } lock (ContactLock.Locker) { //Need to do something about thread being aborted exception var stackTrace = new System.Diagnostics.StackTrace(); var stack = stackTrace.GetFrame(1).GetMethod().Name; var item = new BackgroundInformation(action, String.Format("Error:\n{0}\n{1}\n{2}\n{3}", error.Message, error.StackTrace, stack, stackTrace)); var currentDirectory = HttpRuntime.AppDomainAppPath; var logs = currentDirectory + "\\Logs\\"; if (!Directory.Exists(logs)) { Directory.CreateDirectory(logs); } var path = logs + action + "_" + Guid.NewGuid().ToString(); File.WriteAllText(path, item.Information + "\n" + error.StackTrace); if (error is ThreadAbortException) { return; } if (logInDatabase == true) { using (var session = DataService.OpenSession()) { session.Save(item); session.Flush(); } } } }