diff options
4 files changed, 64 insertions, 66 deletions
diff --git a/win/CS/HandBrake.ApplicationServices/Interop/HandBrakeInstance.cs b/win/CS/HandBrake.ApplicationServices/Interop/HandBrakeInstance.cs index d8f432fc4..f94c6fe24 100644 --- a/win/CS/HandBrake.ApplicationServices/Interop/HandBrakeInstance.cs +++ b/win/CS/HandBrake.ApplicationServices/Interop/HandBrakeInstance.cs @@ -48,8 +48,6 @@ namespace HandBrake.ApplicationServices.Interop /// </summary>
private const double EncodePollIntervalMs = 250;
- private readonly ILog log = LogService.GetLogger();
-
/// <summary>
/// The native handle to the HandBrake instance.
/// </summary>
@@ -246,7 +244,7 @@ namespace HandBrake.ApplicationServices.Interop catch (Exception exc)
{
Debug.WriteLine(exc);
- this.log.LogMessage(exc.ToString(), LogMessageType.API, LogLevel.Error);
+ HandBrakeUtils.SendErrorEvent(exc.ToString());
}
};
this.scanPollTimer.Start();
@@ -480,7 +478,6 @@ namespace HandBrake.ApplicationServices.Interop {
IntPtr json = HBFunctions.hb_get_state_json(this.hbHandle);
string statusJson = Marshal.PtrToStringAnsi(json);
- this.log.LogMessage(statusJson, LogMessageType.Progress, LogLevel.Trace);
JsonState state = null;
if (!string.IsNullOrEmpty(statusJson))
{
@@ -502,14 +499,9 @@ namespace HandBrake.ApplicationServices.Interop var jsonMsg = HBFunctions.hb_get_title_set_json(this.hbHandle);
this.titlesJson = InteropUtilities.ToStringFromUtf8Ptr(jsonMsg);
- this.log.LogMessage(this.titlesJson, LogMessageType.Progress, LogLevel.Trace);
- if (string.IsNullOrEmpty(this.titlesJson))
- {
- this.log.LogMessage("Scan Error: No Scan Data Returned.", LogMessageType.API, LogLevel.Error);
- }
- else
- {
+ if (!string.IsNullOrEmpty(this.titlesJson))
+ {
this.titles = JsonConvert.DeserializeObject<JsonScanObject>(this.titlesJson);
if (this.titles != null)
{
@@ -533,8 +525,6 @@ namespace HandBrake.ApplicationServices.Interop IntPtr json = HBFunctions.hb_get_state_json(this.hbHandle);
string statusJson = Marshal.PtrToStringAnsi(json);
- this.log.LogMessage(statusJson, LogMessageType.Progress, LogLevel.Trace);
-
JsonState state = JsonConvert.DeserializeObject<JsonState>(statusJson);
TaskState taskState = state != null ? TaskState.FromRepositoryValue(state.State) : null;
diff --git a/win/CS/HandBrake.ApplicationServices/Interop/HandBrakePresetService.cs b/win/CS/HandBrake.ApplicationServices/Interop/HandBrakePresetService.cs index ae3387006..e3667a966 100644 --- a/win/CS/HandBrake.ApplicationServices/Interop/HandBrakePresetService.cs +++ b/win/CS/HandBrake.ApplicationServices/Interop/HandBrakePresetService.cs @@ -17,9 +17,6 @@ namespace HandBrake.ApplicationServices.Interop using HandBrake.ApplicationServices.Interop.HbLib;
using HandBrake.ApplicationServices.Interop.Helpers;
using HandBrake.ApplicationServices.Interop.Json.Presets;
- using HandBrake.ApplicationServices.Services.Logging;
- using HandBrake.ApplicationServices.Services.Logging.Interfaces;
- using HandBrake.ApplicationServices.Services.Logging.Model;
using Newtonsoft.Json;
@@ -28,8 +25,6 @@ namespace HandBrake.ApplicationServices.Interop /// </summary>
public class HandBrakePresetService
{
- private static readonly ILog log = LogService.GetLogger();
-
/// <summary>
/// The get built in presets.
/// Requires an hb_init to have been invoked.
@@ -41,9 +36,6 @@ namespace HandBrake.ApplicationServices.Interop {
IntPtr presets = HBFunctions.hb_presets_builtin_get_json();
string presetJson = Marshal.PtrToStringAnsi(presets);
-
- log.LogMessage(presetJson, LogMessageType.API, LogLevel.Debug);
-
IList<PresetCategory> presetList = JsonConvert.DeserializeObject<IList<PresetCategory>>(presetJson);
return presetList;
@@ -62,7 +54,6 @@ namespace HandBrake.ApplicationServices.Interop {
IntPtr presetStringPointer = HBFunctions.hb_presets_read_file_json(InteropUtilities.ToUtf8PtrFromString(filename));
string presetJson = Marshal.PtrToStringAnsi(presetStringPointer);
- log.LogMessage(presetJson, LogMessageType.API, LogLevel.Debug);
if (!string.IsNullOrEmpty(presetJson))
{
diff --git a/win/CS/HandBrake.ApplicationServices/Interop/HandBrakeUtils.cs b/win/CS/HandBrake.ApplicationServices/Interop/HandBrakeUtils.cs index b8fb24778..b16300fb4 100644 --- a/win/CS/HandBrake.ApplicationServices/Interop/HandBrakeUtils.cs +++ b/win/CS/HandBrake.ApplicationServices/Interop/HandBrakeUtils.cs @@ -28,8 +28,6 @@ namespace HandBrake.ApplicationServices.Interop /// </summary>
public static class HandBrakeUtils
{
- private static readonly ILog log = LogService.GetLogger();
-
/// <summary>
/// The callback for log messages from HandBrake.
/// </summary>
@@ -298,7 +296,6 @@ namespace HandBrake.ApplicationServices.Interop public static Geometry GetAnamorphicSize(AnamorphicGeometry anamorphicGeometry)
{
string encode = JsonConvert.SerializeObject(anamorphicGeometry, Formatting.Indented, new JsonSerializerSettings { NullValueHandling = NullValueHandling.Ignore });
- log.LogMessage(encode, LogMessageType.API, LogLevel.Debug);
IntPtr json = HBFunctions.hb_set_anamorphic_size_json(Marshal.StringToHGlobalAnsi(encode));
string result = Marshal.PtrToStringAnsi(json);
return JsonConvert.DeserializeObject<Geometry>(result);
@@ -333,13 +330,9 @@ namespace HandBrake.ApplicationServices.Interop /// <param name="message">
/// The message to send.
/// </param>
- private static void SendMessageEvent(string message)
+ public static void SendMessageEvent(string message)
{
- if (MessageLogged != null)
- {
- log.LogMessage(message, LogMessageType.ScanOrEncode, LogLevel.Info);
- MessageLogged(null, new MessageLoggedEventArgs(message));
- }
+ MessageLogged?.Invoke(null, new MessageLoggedEventArgs(message));
}
/// <summary>
@@ -348,13 +341,9 @@ namespace HandBrake.ApplicationServices.Interop /// <param name="message">
/// The message to send
/// </param>
- private static void SendErrorEvent(string message)
+ public static void SendErrorEvent(string message)
{
- if (ErrorLogged != null)
- {
- log.LogMessage(message, LogMessageType.ScanOrEncode, LogLevel.Error);
- ErrorLogged(null, new MessageLoggedEventArgs(message));
- }
+ ErrorLogged?.Invoke(null, new MessageLoggedEventArgs(message));
}
}
}
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); + } } } |