diff options
author | sr55 <[email protected]> | 2018-05-08 21:26:35 +0100 |
---|---|---|
committer | sr55 <[email protected]> | 2018-05-08 21:26:35 +0100 |
commit | 1a16ebead7e49a214276859f53ce18a0c844f102 (patch) | |
tree | af8bdfb94e31353c30d5eb0e0e30c4171e168e9a /win/CS/HandBrake.ApplicationServices/Services/Logging | |
parent | d04722a3e9002b6e988403b4743ce86b20b2533c (diff) |
WinGui: Remove the need for ILog on the key Interop API surface.
Diffstat (limited to 'win/CS/HandBrake.ApplicationServices/Services/Logging')
-rw-r--r-- | win/CS/HandBrake.ApplicationServices/Services/Logging/LogService.cs | 86 |
1 files changed, 57 insertions, 29 deletions
diff --git a/win/CS/HandBrake.ApplicationServices/Services/Logging/LogService.cs b/win/CS/HandBrake.ApplicationServices/Services/Logging/LogService.cs index b0195ed50..78296795c 100644 --- a/win/CS/HandBrake.ApplicationServices/Services/Logging/LogService.cs +++ b/win/CS/HandBrake.ApplicationServices/Services/Logging/LogService.cs @@ -19,6 +19,8 @@ namespace HandBrake.ApplicationServices.Services.Logging using System.Linq; using System.Text; + using HandBrake.ApplicationServices.Interop; + using HandBrake.ApplicationServices.Interop.EventArgs; using HandBrake.ApplicationServices.Services.Logging.EventArgs; using HandBrake.ApplicationServices.Services.Logging.Interfaces; using HandBrake.ApplicationServices.Services.Logging.Model; @@ -46,6 +48,12 @@ namespace HandBrake.ApplicationServices.Services.Logging private StreamWriter fileWriter; private string logHeader; + public LogService() + { + HandBrakeUtils.MessageLogged += this.HandBrakeUtils_MessageLogged; + HandBrakeUtils.ErrorLogged += this.HandBrakeUtils_ErrorLogged; + } + /// <summary> /// Fires when a new QueueTask starts /// </summary> @@ -285,35 +293,6 @@ namespace HandBrake.ApplicationServices.Services.Logging } /// <summary> - /// Helper method for logging content to disk - /// </summary> - /// <param name="msg"> - /// Log message to write. - /// </param> - private void LogMessageToDisk(LogMessage msg) - { - if (!this.isDiskLoggingEnabled) - { - return; - } - - try - { - lock (this.fileWriterLock) - { - if (this.fileWriter != null && this.fileWriter.BaseStream.CanWrite) - { - this.fileWriter.WriteLine(msg.Content); - } - } - } - catch (Exception exc) - { - Debug.WriteLine(exc); // This exception doesn't warrant user interaction, but it should be logged - } - } - - /// <summary> /// Called when a log message is created. /// </summary> /// <param name="msg"> @@ -360,5 +339,54 @@ namespace HandBrake.ApplicationServices.Services.Logging { this.LogReset?.Invoke(this, System.EventArgs.Empty); } + + /// <summary> + /// Helper method for logging content to disk + /// </summary> + /// <param name="msg"> + /// Log message to write. + /// </param> + private void LogMessageToDisk(LogMessage msg) + { + if (!this.isDiskLoggingEnabled) + { + return; + } + + try + { + lock (this.fileWriterLock) + { + if (this.fileWriter != null && this.fileWriter.BaseStream.CanWrite) + { + this.fileWriter.WriteLine(msg.Content); + } + } + } + catch (Exception exc) + { + Debug.WriteLine(exc); // This exception doesn't warrant user interaction, but it should be logged + } + } + + private void HandBrakeUtils_ErrorLogged(object sender, MessageLoggedEventArgs e) + { + if (e == null || string.IsNullOrEmpty(e.Message)) + { + return; + } + + this.LogMessage(e.Message, LogMessageType.ScanOrEncode, LogLevel.Error); + } + + private void HandBrakeUtils_MessageLogged(object sender, MessageLoggedEventArgs e) + { + if (e == null || string.IsNullOrEmpty(e.Message)) + { + return; + } + + this.LogMessage(e.Message, LogMessageType.ScanOrEncode, LogLevel.Info); + } } } |