Improved logging for file decrypt

This commit is contained in:
Robert McRackan 2019-11-26 13:13:16 -05:00
parent 1cecd4ba2e
commit 57bc74cd23
2 changed files with 22 additions and 17 deletions

View File

@ -8,7 +8,13 @@ namespace LibationWinForm.BookLiberation
{
public partial class DecryptForm : Form
{
public DecryptForm()
class SerilogTextWriter : System.IO.TextWriter
{
public override System.Text.Encoding Encoding => System.Text.Encoding.ASCII;
public override void WriteLine(string value) => Serilog.Log.Logger.Debug(value);
}
public DecryptForm()
{
InitializeComponent();
}
@ -18,7 +24,7 @@ namespace LibationWinForm.BookLiberation
{
// redirect Console.WriteLine to console, textbox
var controlWriter = new RichTextBoxTextWriter(this.rtbLog);
var multiLogger = new MultiTextWriter(origOut, controlWriter);
var multiLogger = new MultiTextWriter(origOut, controlWriter, new SerilogTextWriter());
Console.SetOut(multiLogger);
}
@ -57,19 +63,6 @@ namespace LibationWinForm.BookLiberation
public void SetCoverImage(byte[] coverBytes)
=> pictureBox1.UIThread(() => pictureBox1.Image = ImageReader.ToImage(coverBytes));
public void AppendError(Exception ex)
{
Serilog.Log.Logger.Error(ex, "Decrypt form: error");
appendText("ERROR: " + ex.Message);
}
public void AppendText(string text)
{
Serilog.Log.Logger.Debug($"Decrypt form: {text}");
appendText(text);
}
private void appendText(string text) => Console.WriteLine($"{DateTime.Now} {text}");
public void UpdateProgress(int percentage) => progressBar1.UIThread(() => progressBar1.Value = percentage);
}
}

View File

@ -109,8 +109,20 @@ namespace LibationWinForm
.Select(sp => sp.Book)
.ToList();
setBookBackupCounts(books);
setPdfBackupCounts(books);
// will often fail once if book has been moved while libation is closed. just retry once for now
// fix actual issue later
// FilePathCache.GetPath() :: inMemoryCache.SingleOrDefault(i => i.Id == id && i.FileType == type)
try
{
setBookBackupCounts(books);
setPdfBackupCounts(books);
}
catch (Exception ex)
{
System.Threading.Thread.Sleep(100);
setBookBackupCounts(books);
setPdfBackupCounts(books);
}
}
enum AudioFileState { full, aax, none }
private void setBookBackupCounts(IEnumerable<Book> books)