Fixed logging bug in single-book liberation
This commit is contained in:
parent
cd3e0dba68
commit
8f487894f5
@ -13,7 +13,7 @@
|
|||||||
<!-- <PublishSingleFile>true</PublishSingleFile> -->
|
<!-- <PublishSingleFile>true</PublishSingleFile> -->
|
||||||
<RuntimeIdentifier>win-x64</RuntimeIdentifier>
|
<RuntimeIdentifier>win-x64</RuntimeIdentifier>
|
||||||
|
|
||||||
<Version>5.0.0.5</Version>
|
<Version>5.1.0.1</Version>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
|||||||
@ -15,21 +15,28 @@ namespace LibationWinForms.BookLiberation
|
|||||||
public event EventHandler<string> LogErrorString;
|
public event EventHandler<string> LogErrorString;
|
||||||
public event EventHandler<(Exception, string)> LogError;
|
public event EventHandler<(Exception, string)> LogError;
|
||||||
|
|
||||||
public static LogMe RegisterForm(AutomatedBackupsForm form)
|
private LogMe()
|
||||||
|
{
|
||||||
|
LogInfo += (_, text) => Serilog.Log.Logger.Information($"Automated backup: {text}");
|
||||||
|
LogErrorString += (_, text) => Serilog.Log.Logger.Error(text);
|
||||||
|
LogError += (_, tuple) => Serilog.Log.Logger.Error(tuple.Item1, tuple.Item2 ?? "Automated backup: error");
|
||||||
|
}
|
||||||
|
|
||||||
|
public static LogMe RegisterForm(AutomatedBackupsForm form = null)
|
||||||
{
|
{
|
||||||
var logMe = new LogMe();
|
var logMe = new LogMe();
|
||||||
|
|
||||||
logMe.LogInfo += (_, text) => Serilog.Log.Logger.Information($"Automated backup: {text}");
|
if (form is null)
|
||||||
logMe.LogInfo += (_, text) => form.WriteLine(text);
|
return logMe;
|
||||||
|
|
||||||
logMe.LogErrorString += (_, text) => Serilog.Log.Logger.Error(text);
|
logMe.LogInfo += (_, text) => form?.WriteLine(text);
|
||||||
logMe.LogErrorString += (_, text) => form.WriteLine(text);
|
|
||||||
|
logMe.LogErrorString += (_, text) => form?.WriteLine(text);
|
||||||
|
|
||||||
logMe.LogError += (_, tuple) => Serilog.Log.Logger.Error(tuple.Item1, tuple.Item2 ?? "Automated backup: error");
|
|
||||||
logMe.LogError += (_, tuple) =>
|
logMe.LogError += (_, tuple) =>
|
||||||
{
|
{
|
||||||
form.WriteLine(tuple.Item2 ?? "Automated backup: error");
|
form?.WriteLine(tuple.Item2 ?? "Automated backup: error");
|
||||||
form.WriteLine("ERROR: " + tuple.Item1.Message);
|
form?.WriteLine("ERROR: " + tuple.Item1.Message);
|
||||||
};
|
};
|
||||||
|
|
||||||
return logMe;
|
return logMe;
|
||||||
@ -48,13 +55,13 @@ namespace LibationWinForms.BookLiberation
|
|||||||
|
|
||||||
var backupBook = getWiredUpBackupBook(completedAction);
|
var backupBook = getWiredUpBackupBook(completedAction);
|
||||||
|
|
||||||
(Action unsibscribeEvents, LogMe logMe) = attachToBackupsForm(backupBook);
|
(Action unsubscribeEvents, LogMe logMe) = attachToBackupsForm(backupBook);
|
||||||
|
|
||||||
var libraryBook = IProcessableExt.GetSingleLibraryBook(productId);
|
var libraryBook = IProcessableExt.GetSingleLibraryBook(productId);
|
||||||
// continue even if libraryBook is null. we'll display even that in the processing box
|
// continue even if libraryBook is null. we'll display even that in the processing box
|
||||||
await new BackupSingle(logMe, backupBook, libraryBook).RunBackupAsync();
|
await new BackupSingle(logMe, backupBook, libraryBook).RunBackupAsync();
|
||||||
|
|
||||||
unsibscribeEvents();
|
unsubscribeEvents();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static async Task BackupAllBooksAsync(EventHandler<LibraryBook> completedAction = null)
|
public static async Task BackupAllBooksAsync(EventHandler<LibraryBook> completedAction = null)
|
||||||
@ -64,11 +71,11 @@ namespace LibationWinForms.BookLiberation
|
|||||||
var backupBook = getWiredUpBackupBook(completedAction);
|
var backupBook = getWiredUpBackupBook(completedAction);
|
||||||
var automatedBackupsForm = new AutomatedBackupsForm();
|
var automatedBackupsForm = new AutomatedBackupsForm();
|
||||||
|
|
||||||
(Action unsibscribeEvents, LogMe logMe) = attachToBackupsForm(backupBook, automatedBackupsForm);
|
(Action unsubscribeEvents, LogMe logMe) = attachToBackupsForm(backupBook, automatedBackupsForm);
|
||||||
|
|
||||||
await new BackupLoop(logMe, backupBook, automatedBackupsForm).RunBackupAsync();
|
await new BackupLoop(logMe, backupBook, automatedBackupsForm).RunBackupAsync();
|
||||||
|
|
||||||
unsibscribeEvents();
|
unsubscribeEvents();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static BackupBook getWiredUpBackupBook(EventHandler<LibraryBook> completedAction)
|
private static BackupBook getWiredUpBackupBook(EventHandler<LibraryBook> completedAction)
|
||||||
@ -98,10 +105,10 @@ namespace LibationWinForms.BookLiberation
|
|||||||
|
|
||||||
private static void updateIsLiberated(object sender, LibraryBook e) => ApplicationServices.SearchEngineCommands.UpdateIsLiberated(e.Book);
|
private static void updateIsLiberated(object sender, LibraryBook e) => ApplicationServices.SearchEngineCommands.UpdateIsLiberated(e.Book);
|
||||||
|
|
||||||
private static (Action unsibscribeEvents, LogMe) attachToBackupsForm(BackupBook backupBook, AutomatedBackupsForm automatedBackupsForm = null)
|
private static (Action unsubscribeEvents, LogMe) attachToBackupsForm(BackupBook backupBook, AutomatedBackupsForm automatedBackupsForm = null)
|
||||||
{
|
{
|
||||||
#region create logger
|
#region create logger
|
||||||
var logMe = automatedBackupsForm is null? new LogMe() : LogMe.RegisterForm(automatedBackupsForm);
|
var logMe = LogMe.RegisterForm(automatedBackupsForm);
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region define how model actions will affect form behavior
|
#region define how model actions will affect form behavior
|
||||||
@ -125,7 +132,7 @@ namespace LibationWinForms.BookLiberation
|
|||||||
|
|
||||||
#region when form closes, unsubscribe from model's events
|
#region when form closes, unsubscribe from model's events
|
||||||
// unsubscribe so disposed forms aren't still trying to receive notifications
|
// unsubscribe so disposed forms aren't still trying to receive notifications
|
||||||
Action unsibscribe = () =>
|
Action unsubscribe = () =>
|
||||||
{
|
{
|
||||||
backupBook.DecryptBook.Begin -= decryptBookBegin;
|
backupBook.DecryptBook.Begin -= decryptBookBegin;
|
||||||
backupBook.DecryptBook.StatusUpdate -= statusUpdate;
|
backupBook.DecryptBook.StatusUpdate -= statusUpdate;
|
||||||
@ -136,7 +143,7 @@ namespace LibationWinForms.BookLiberation
|
|||||||
};
|
};
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
return (unsibscribe, logMe);
|
return (unsubscribe, logMe);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static async Task BackupAllPdfsAsync(EventHandler<LibraryBook> completedAction = null)
|
public static async Task BackupAllPdfsAsync(EventHandler<LibraryBook> completedAction = null)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user