public async Task ReportAsync(string message) { if (string.IsNullOrWhiteSpace(message)) { throw new ArgumentNullException(nameof(message)); } Logs.Add(new Log(DateTime.Now, $"{DateTime.Now}: Sending message to {ConnectionString}....")); _logger.Log(SentryLevel.Info, $"{DateTime.Now}: Sending message to {ConnectionString}...."); await Client.PostAsync(ConnectionString, new StringContent("{\"text\":\"BackupSaver: " + message + "\"}")); Logs.Add(new Log(DateTime.Now, $"{DateTime.Now}: Successfully...")); _logger.Log(SentryLevel.Info, $"{DateTime.Now}: Successfully..."); }
public void Log(SentryLevel logLevel, string message, Exception exception = null, params object[] args) { switch (logLevel) { case SentryLevel.Fatal: InternalLogger.Fatal(exception, message, args); break; case SentryLevel.Error: InternalLogger.Error(exception, message, args); break; case SentryLevel.Warning: InternalLogger.Warn(exception, message, args); break; case SentryLevel.Info: InternalLogger.Info(exception, message, args); break; default: InternalLogger.Debug(exception, message, args); break; } if (_extraLogger?.IsEnabled(logLevel) == true) { _extraLogger.Log(logLevel, message, exception, args); } }
internal static void LogIfEnabled( this IDiagnosticLogger logger, SentryLevel level, string message, Exception?exception = null) { if (logger.IsEnabled(level)) { logger.Log(level, message, exception); } }
public async Task <string> MakeBackupAsync() { Environment.SetEnvironmentVariable("PGPASSWORD", Config.Password); Logs.Add(new Log(DateTime.Now, $"{DateTime.Now}: Set PGPASSWORD...")); _logger.Log(SentryLevel.Info, $"{DateTime.Now}: Set PGPASSWORD..."); Logs.Add(new Log(DateTime.Now, $"{DateTime.Now}: Successfully...")); _logger.Log(SentryLevel.Info, $"{DateTime.Now}: Successfully..."); string outFilePath = Path.Combine( Path.GetTempPath(), "backup", $"{DateTime.Now:yyyy-dd-M--HH-mm-ss}"); Directory.CreateDirectory(outFilePath); var databases = await GetDbListAsync(); Logs.Add(new Log(DateTime.Now, $"{DateTime.Now}: Creating sql files....")); _logger.Log(SentryLevel.Info, $"{DateTime.Now}: Creating sql files...."); await CreateSqlFilesAsync(databases, outFilePath, Config) .ConfigureAwait(false); if (!Directory.EnumerateFiles(outFilePath, "*.*", SearchOption.AllDirectories).Any()) { throw new DirectoryIsEmptyException("Failed to make dumps. Check the connection"); } Logs.Add(new Log(DateTime.Now, $"{DateTime.Now}: Successfully...")); _logger.Log(SentryLevel.Info, $"{DateTime.Now}: Successfully..."); string archivePath = await CreateArchiveAsync(outFilePath, $"{DateTime.Now:yyyy-dd-M--HH-mm-ss}") .ConfigureAwait(false); Logs.Add(new Log(DateTime.Now, $"{DateTime.Now}: Removing intermediate folder {Path.GetFileNameWithoutExtension(outFilePath)}...")); _logger.Log(SentryLevel.Info, $"{DateTime.Now}: Removing intermediate folder {Path.GetFileNameWithoutExtension(outFilePath)}..."); if (Directory.Exists(outFilePath)) { Directory.Delete(outFilePath, true); } Logs.Add(new Log(DateTime.Now, $"{DateTime.Now}: The backups {databases.ToFormatString()} were successfully archived and compressed." + $"Archive weight: {new FileInfo(archivePath).Length} Bytes")); _logger.Log(SentryLevel.Info, $"{DateTime.Now}: The backups {databases.ToFormatString()} were successfully archived and compressed." + $"Archive weight: {new FileInfo(archivePath).Length} Bytes"); return(archivePath); }
internal static void LogIfEnabled <TArg>( this IDiagnosticLogger logger, SentryLevel level, Exception?exception, string message, TArg arg) { if (logger.IsEnabled(level)) { logger.Log(level, message, exception, arg); } }
internal static void LogIfEnabled <TArg, TArg2>( this IDiagnosticLogger logger, SentryLevel level, string message, TArg arg, TArg2 arg2, Exception exception = null) { if (logger?.IsEnabled(level) == true) { logger.Log(level, message, exception, arg, arg2); } }
public async Task SaveAsync(string source) { if (string.IsNullOrEmpty(source)) { throw new ArgumentNullException(nameof(source)); } Logs.Add(new Log(DateTime.Now, $"{DateTime.Now}: Creating directory hierarchy in AmazonS3...")); _logger.Log(SentryLevel.Info, $"{DateTime.Now}: Creating directory hierarchy..."); await CreateDirectoryHierarchyAsync(); Logs.Add(new Log(DateTime.Now, $"{DateTime.Now}: Successfully creating directory hierarchy in AmazonS3...")); _logger.Log(SentryLevel.Info, $"{DateTime.Now}: Successfully creating directory hierarchy in AmazonS3..."); Logs.Add(new Log(DateTime.Now, $"{DateTime.Now}: Constructing putBackupFileRequest....")); _logger.Log(SentryLevel.Info, $"{DateTime.Now}: Constructing putBackupFileRequest...."); var putBackupFileRequest = ConstructPutObjectRequest(Bucket, $"{DateTime.Now.Year}" + "/" + $"{DateTime.Now.Month}" + "/" + $"{DateTime.Now.Day}" + "/" + Path.GetFileNameWithoutExtension(source), source); Logs.Add(new Log(DateTime.Now, $"{DateTime.Now}: Successfully")); _logger.Log(SentryLevel.Info, $"{DateTime.Now}: Successfully"); Logs.Add(new Log(DateTime.Now, $"{DateTime.Now}: Upload {Path.GetFileNameWithoutExtension(source)}...")); _logger.Log(SentryLevel.Info, $"{DateTime.Now}: Upload {Path.GetFileNameWithoutExtension(source)}..."); await Client.PutObjectAsync(putBackupFileRequest); Logs.Add(new Log(DateTime.Now, $"{DateTime.Now}: Successfully saved {Path.GetFileNameWithoutExtension(source)}." + $"Weight: {new FileInfo(source).Length} Bytes")); _logger.Log(SentryLevel.Info, $"{DateTime.Now}: Successfully saved {Path.GetFileNameWithoutExtension(source)}." + $"Weight: {new FileInfo(source).Length} Bytes"); }