diff options
author | sr55 <[email protected]> | 2019-12-28 13:50:55 +0000 |
---|---|---|
committer | sr55 <[email protected]> | 2019-12-28 13:50:55 +0000 |
commit | 741d9e082ba0f40c4571f48b54eb237048df8c2a (patch) | |
tree | b851dad93de1cfae8aa127ef885cf8a3a347c425 /win/CS/HandBrakeWPF | |
parent | 0ca1b03b3d3801b3db8661fd26e461ad2ca2e05f (diff) |
WinGui: First step in a long overdue cleanup of the logging code. Stripped out a bunch of unneeded code
Diffstat (limited to 'win/CS/HandBrakeWPF')
16 files changed, 125 insertions, 390 deletions
diff --git a/win/CS/HandBrakeWPF/Helpers/LogManager.cs b/win/CS/HandBrakeWPF/Helpers/LogManager.cs index 6a281fb64..429c5f971 100644 --- a/win/CS/HandBrakeWPF/Helpers/LogManager.cs +++ b/win/CS/HandBrakeWPF/Helpers/LogManager.cs @@ -11,62 +11,22 @@ namespace HandBrakeWPF.Helpers { using System.IO; - using HandBrake.Interop.Interop; + using Caliburn.Micro; + + using HandBrake.Worker.Logging.Models; using HandBrakeWPF.Utilities; using ILog = HandBrakeWPF.Services.Logging.Interfaces.ILog; - using LogService = HandBrakeWPF.Services.Logging.LogService; - /// <summary> - /// Tempory Class to Initialise the logging. - /// </summary> public static class LogManager { - /// <summary> - /// The init. - /// </summary> public static void Init() { - ILog log = LogService.GetLogger(); + ILog log = IoC.Get<ILog>(); string logDir = DirectoryUtilities.GetLogDirectory(); string logFile = Path.Combine(logDir, string.Format("activity_log{0}.txt", GeneralUtilities.ProcessId)); - if (!Directory.Exists(Path.GetDirectoryName(logFile))) - { - Directory.CreateDirectory(Path.GetDirectoryName(logFile)); - } - - log.Enable(); - log.SetupLogHeader(GeneralUtilities.CreateLogHeader().ToString()); - log.EnableLoggingToDisk(logFile, true); - HandBrakeUtils.MessageLogged += HandBrakeUtils_MessageLogged; - HandBrakeUtils.ErrorLogged += HandBrakeUtils_ErrorLogged; - } - - /// <summary> - /// Subscribe the ErrorLogged event. - /// </summary> - /// <param name="sender"> - /// The sender. - /// </param> - /// <param name="e"> - /// The e. - /// </param> - private static void HandBrakeUtils_ErrorLogged(object sender, HandBrake.Interop.Interop.EventArgs.MessageLoggedEventArgs e) - { - } - - /// <summary> - /// Subscribe the MessageLogged event. - /// </summary> - /// <param name="sender"> - /// The sender. - /// </param> - /// <param name="e"> - /// The e. - /// </param> - private static void HandBrakeUtils_MessageLogged(object sender, HandBrake.Interop.Interop.EventArgs.MessageLoggedEventArgs e) - { + log.ConfigureLogging(new LogHandlerConfig(true, logFile, true, GeneralUtilities.CreateLogHeader().ToString())); } } }
\ No newline at end of file diff --git a/win/CS/HandBrakeWPF/Services/Encode/EncodeBase.cs b/win/CS/HandBrakeWPF/Services/Encode/EncodeBase.cs index c28b3cebd..300f27f15 100644 --- a/win/CS/HandBrakeWPF/Services/Encode/EncodeBase.cs +++ b/win/CS/HandBrakeWPF/Services/Encode/EncodeBase.cs @@ -34,11 +34,11 @@ namespace HandBrakeWPF.Services.Encode /// </summary> public class EncodeBase { - /// <summary> - /// Initializes a new instance of the <see cref="EncodeBase"/> class. - /// </summary> - public EncodeBase() - { + private readonly ILog logService; + + public EncodeBase(ILog logService) + { + this.logService = logService; } #region Events @@ -132,8 +132,7 @@ namespace HandBrakeWPF.Services.Encode string encodeDestinationPath = Path.GetDirectoryName(destination); string destinationFile = Path.GetFileName(destination); string encodeLogFile = destinationFile + " " + DateTime.Now.ToString(CultureInfo.InvariantCulture).Replace("/", "-").Replace(":", "-") + ".txt"; - ILog log = LogService.GetLogger(); - string logContent = log.ActivityLog; + string logContent = this.logService.ActivityLog; // Make sure the log directory exists. if (!Directory.Exists(logDir)) diff --git a/win/CS/HandBrakeWPF/Services/Encode/LibEncode.cs b/win/CS/HandBrakeWPF/Services/Encode/LibEncode.cs index 5c147aa4e..eb24d721e 100644 --- a/win/CS/HandBrakeWPF/Services/Encode/LibEncode.cs +++ b/win/CS/HandBrakeWPF/Services/Encode/LibEncode.cs @@ -28,8 +28,6 @@ namespace HandBrakeWPF.Services.Encode using HandBrakeInstanceManager = Instance.HandBrakeInstanceManager; using IEncode = Interfaces.IEncode; using ILog = Logging.Interfaces.ILog; - using LogLevel = Logging.Model.LogLevel; - using LogMessageType = Logging.Model.LogMessageType; using LogService = Logging.LogService; /// <summary> @@ -39,7 +37,7 @@ namespace HandBrakeWPF.Services.Encode { #region Private Variables - private ILog log = LogService.GetLogger(); + private readonly ILog log; private readonly IHbFunctionsProvider hbFunctionsProvider; private IEncodeInstance instance; private DateTime startTime; @@ -49,8 +47,9 @@ namespace HandBrakeWPF.Services.Encode #endregion - public LibEncode(IHbFunctionsProvider hbFunctionsProvider) + public LibEncode(IHbFunctionsProvider hbFunctionsProvider, ILog logService) : base(logService) { + this.log = logService; this.hbFunctionsProvider = hbFunctionsProvider; } @@ -200,12 +199,12 @@ namespace HandBrakeWPF.Services.Encode /// <param name="message">Log message content</param> protected void ServiceLogMessage(string message) { - this.log.LogMessage(string.Format("{0}# {1}{0}", Environment.NewLine, message), LogMessageType.ScanOrEncode, LogLevel.Info); + this.log.LogMessage(string.Format("{0}# {1}{0}", Environment.NewLine, message)); } protected void TimedLogMessage(string message) { - this.log.LogMessage(string.Format("[{0}] {1}", DateTime.Now.ToString("hh:mm:ss"), message), LogMessageType.ScanOrEncode, LogLevel.Info); + this.log.LogMessage(string.Format("[{0}] {1}", DateTime.Now.ToString("hh:mm:ss"), message)); } /// <summary> diff --git a/win/CS/HandBrakeWPF/Services/Logging/Interfaces/ILog.cs b/win/CS/HandBrakeWPF/Services/Logging/Interfaces/ILog.cs index d0f5949a2..07f3ea635 100644 --- a/win/CS/HandBrakeWPF/Services/Logging/Interfaces/ILog.cs +++ b/win/CS/HandBrakeWPF/Services/Logging/Interfaces/ILog.cs @@ -12,10 +12,10 @@ namespace HandBrakeWPF.Services.Logging.Interfaces using System; using System.Collections.Generic; + using HandBrake.Worker.Logging.Models; + using LogEventArgs = HandBrakeWPF.Services.Logging.EventArgs.LogEventArgs; - using LogLevel = HandBrakeWPF.Services.Logging.Model.LogLevel; using LogMessage = HandBrakeWPF.Services.Logging.Model.LogMessage; - using LogMessageType = HandBrakeWPF.Services.Logging.Model.LogMessageType; /// <summary> /// The Log interface. @@ -48,9 +48,15 @@ namespace HandBrakeWPF.Services.Logging.Interfaces void Reset(); /// <summary> - /// The enable. + /// Enable logging for this worker process. /// </summary> - void Enable(); + /// <param name="config"> + /// Configuration for the logger. + /// </param> + /// <remarks> + /// If this is not called, all log messages from libhb will be ignored. + /// </remarks> + void ConfigureLogging(LogHandlerConfig config); /// <summary> /// Log a message. @@ -58,31 +64,6 @@ namespace HandBrakeWPF.Services.Logging.Interfaces /// <param name="content"> /// The content of the log message, /// </param> - /// <param name="type"> - /// The Message Type. (i.e. where it came from) - /// </param> - /// <param name="level"> - /// The log level - /// </param> - void LogMessage(string content, LogMessageType type, LogLevel level); - - /// <summary> - /// Enable Logging to Disk - /// </summary> - /// <param name="logFile"> - /// The log file to write to. - /// </param> - /// <param name="deleteCurrentLogFirst"> - /// Delete the current log file if it exists. - /// </param> - void EnableLoggingToDisk(string logFile, bool deleteCurrentLogFirst); - - /// <summary> - /// The setup log header. - /// </summary> - /// <param name="header"> - /// The header. - /// </param> - void SetupLogHeader(string header); + void LogMessage(string content); } }
\ No newline at end of file diff --git a/win/CS/HandBrakeWPF/Services/Logging/LogService.cs b/win/CS/HandBrakeWPF/Services/Logging/LogService.cs index 03f6c100e..3bc4c2b5b 100644 --- a/win/CS/HandBrakeWPF/Services/Logging/LogService.cs +++ b/win/CS/HandBrakeWPF/Services/Logging/LogService.cs @@ -21,16 +21,12 @@ namespace HandBrakeWPF.Services.Logging using HandBrake.Interop.Interop; using HandBrake.Interop.Interop.EventArgs; + using HandBrake.Worker.Logging.Models; using ILog = Interfaces.ILog; using LogEventArgs = EventArgs.LogEventArgs; - using LogLevel = Model.LogLevel; using LogMessage = Model.LogMessage; - using LogMessageType = Model.LogMessageType; - /// <summary> - /// The log helper. - /// </summary> public class LogService : ILog { // TODO List. @@ -41,7 +37,6 @@ namespace HandBrakeWPF.Services.Logging private readonly object fileWriterLock = new object(); private readonly StringBuilder logBuilder = new StringBuilder(); - private LogLevel currentLogLevel = LogLevel.Error; private bool isLoggingEnabled; private List<LogMessage> logMessages = new List<LogMessage>(); private long messageIndex; @@ -57,19 +52,10 @@ namespace HandBrakeWPF.Services.Logging HandBrakeUtils.ErrorLogged += this.HandBrakeUtils_ErrorLogged; } - /// <summary> - /// Fires when a new QueueTask starts - /// </summary> public event EventHandler<LogEventArgs> MessageLogged; - /// <summary> - /// The log reset event - /// </summary> public event EventHandler LogReset; - /// <summary> - /// Gets the log messages. - /// </summary> public IEnumerable<LogMessage> LogMessages { get @@ -81,9 +67,6 @@ namespace HandBrakeWPF.Services.Logging } } - /// <summary> - /// Gets the Activity Log as a string. - /// </summary> public string ActivityLog { get @@ -95,31 +78,15 @@ namespace HandBrakeWPF.Services.Logging } } - /// <summary> - /// Log message. - /// </summary> - /// <param name="content"> - /// The content. - /// </param> - /// <param name="type"> - /// The type. - /// </param> - /// <param name="level"> - /// The level. - /// </param> - public void LogMessage(string content, LogMessageType type, LogLevel level) + public void LogMessage(string content) { if (!this.isLoggingEnabled) { return; } - if (level > this.currentLogLevel) - { - return; - } - LogMessage msg = new LogMessage(content, type, level, this.messageIndex); + LogMessage msg = new LogMessage(content, this.messageIndex); lock (this.lockObject) { this.messageIndex = this.messageIndex + 1; @@ -130,129 +97,36 @@ namespace HandBrakeWPF.Services.Logging if (this.logMessages.Count > 50000) { this.messageIndex = this.messageIndex + 1; - msg = new LogMessage( - "Log Service Pausing. Too Many Log messages. This may indicate a problem with your encode.", - LogMessageType.Application, - LogLevel.Error, - this.messageIndex); + msg = new LogMessage("Log Service Pausing. Too Many Log messages. This may indicate a problem with your encode.", this.messageIndex); this.logMessages.Add(msg); this.logBuilder.AppendLine(msg.Content); this.LogMessageToDisk(msg); - this.Disable(); + this.isLoggingEnabled = false; } } this.OnMessageLogged(msg); // Must be outside lock to be thread safe. } - /// <summary> - /// Gets an shared instance of the logger. Logging is enabled by default - /// You can turn it off by calling Disable() if you don't want it. - /// </summary> - /// <returns> - /// An instance of this logger. - /// </returns> - public static ILog GetLogger() - { - return loggerInstance ?? (loggerInstance = new LogService()); - } - - /// <summary> - /// The set log level. Default: Info. - /// </summary> - /// <param name="level"> - /// The level. - /// </param> - public void SetLogLevel(LogLevel level) - { - this.currentLogLevel = level; - } - - /// <summary> - /// The enable. - /// </summary> - public void Enable() + public void ConfigureLogging(LogHandlerConfig config) { this.isLoggingEnabled = true; - } - /// <summary> - /// Enable Logging to Disk - /// </summary> - /// <param name="logFile"> - /// The log file to write to. - /// </param> - /// <param name="deleteCurrentLogFirst"> - /// Delete the current log file if it exists. - /// </param> - public void EnableLoggingToDisk(string logFile, bool deleteCurrentLogFirst) - { - if (this.isDiskLoggingEnabled) + if (config.EnableDiskLogging) { - throw new Exception("Disk Logging already enabled!"); - } - - try - { - if (!Directory.Exists(Path.GetDirectoryName(logFile))) - { - throw new Exception("Log Directory does not exist. This service will not create it for you!"); - } - - if (deleteCurrentLogFirst && File.Exists(logFile)) + if (!string.IsNullOrEmpty(config.LogFile) && !Directory.Exists(Path.GetDirectoryName(config.LogFile))) { - File.Delete(logFile); + Directory.CreateDirectory(Path.GetDirectoryName(config.LogFile)); } - this.diskLogPath = logFile; - this.isDiskLoggingEnabled = true; - this.deleteLogFirst = deleteCurrentLogFirst; - - lock (this.fileWriterLock) - { - this.fileWriter = new StreamWriter(logFile) { AutoFlush = true }; - } - } - catch (Exception exc) - { - this.LogMessage("Failed to Initialise Disk Logging. " + Environment.NewLine + exc, LogMessageType.Application, LogLevel.Error); - - if (this.fileWriter != null) - { - lock (this.fileWriterLock) - { - this.fileWriter.Flush(); - this.fileWriter.Close(); - this.fileWriter.Dispose(); - } - } + this.EnableLoggingToDisk(config.LogFile, config.DeleteCurrentLogFirst); } - } - /// <summary> - /// The setup log header. - /// </summary> - /// <param name="header"> - /// The header. - /// </param> - public void SetupLogHeader(string header) - { - this.logHeader = header; - this.LogMessage(header, LogMessageType.Application, LogLevel.Info); + this.logHeader = config.Header; + this.LogMessage(config.Header); } - /// <summary> - /// The disable. - /// </summary> - public void Disable() - { - this.isLoggingEnabled = false; - } - - /// <summary> - /// Clear the log messages collection. - /// </summary> public void Reset() { lock (this.lockObject) @@ -295,12 +169,6 @@ namespace HandBrakeWPF.Services.Logging } } - /// <summary> - /// Called when a log message is created. - /// </summary> - /// <param name="msg"> - /// The Log Message - /// </param> protected virtual void OnMessageLogged(LogMessage msg) { var onMessageLogged = this.MessageLogged; @@ -310,9 +178,6 @@ namespace HandBrakeWPF.Services.Logging } } - /// <summary> - /// Shutdown and Dispose of the File Writer. - /// </summary> protected void ShutdownFileWriter() { try @@ -335,20 +200,61 @@ namespace HandBrakeWPF.Services.Logging } } - /// <summary> - /// Trigger the Event to notify any subscribers that the log has been reset. - /// </summary> protected virtual void OnLogReset() { 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 EnableLoggingToDisk(string logFile, bool deleteCurrentLogFirst) + { + if (this.isDiskLoggingEnabled) + { + throw new Exception("Disk Logging already enabled!"); + } + + try + { + if (!Directory.Exists(Path.GetDirectoryName(logFile))) + { + throw new Exception("Log Directory does not exist. This service will not create it for you!"); + } + + if (deleteCurrentLogFirst && File.Exists(logFile)) + { + File.Delete(logFile); + } + + this.diskLogPath = logFile; + this.isDiskLoggingEnabled = true; + this.deleteLogFirst = deleteCurrentLogFirst; + + lock (this.fileWriterLock) + { + this.fileWriter = new StreamWriter(logFile) { AutoFlush = true }; + } + } + catch (Exception exc) + { + this.LogMessage("Failed to Initialise Disk Logging. " + Environment.NewLine + exc); + + if (this.fileWriter != null) + { + lock (this.fileWriterLock) + { + this.fileWriter.Flush(); + this.fileWriter.Close(); + this.fileWriter.Dispose(); + } + } + } + } + + private void SetupLogHeader(string header) + { + this.logHeader = header; + this.LogMessage(header); + } + private void LogMessageToDisk(LogMessage msg) { if (!this.isDiskLoggingEnabled) @@ -379,7 +285,7 @@ namespace HandBrakeWPF.Services.Logging return; } - this.LogMessage(e.Message, LogMessageType.ScanOrEncode, LogLevel.Error); + this.LogMessage(e.Message); } private void HandBrakeUtils_MessageLogged(object sender, MessageLoggedEventArgs e) @@ -389,7 +295,7 @@ namespace HandBrakeWPF.Services.Logging return; } - this.LogMessage(e.Message, LogMessageType.ScanOrEncode, LogLevel.Info); + this.LogMessage(e.Message); } } } diff --git a/win/CS/HandBrakeWPF/Services/Logging/Model/LogLevel.cs b/win/CS/HandBrakeWPF/Services/Logging/Model/LogLevel.cs deleted file mode 100644 index 07f35e304..000000000 --- a/win/CS/HandBrakeWPF/Services/Logging/Model/LogLevel.cs +++ /dev/null @@ -1,42 +0,0 @@ -// -------------------------------------------------------------------------------------------------------------------- -// <copyright file="LogLevel.cs" company="HandBrake Project (http://handbrake.fr)"> -// This file is part of the HandBrake source code - It may be used under the terms of the GNU General Public License. -// </copyright> -// <summary> -// The log level. -// </summary> -// -------------------------------------------------------------------------------------------------------------------- - -namespace HandBrakeWPF.Services.Logging.Model -{ - /// <summary> - /// The log level. - /// </summary> - public enum LogLevel - { - /// <summary> - /// The info. - /// </summary> - Info, - - /// <summary> - /// The warning. - /// </summary> - Warning, - - /// <summary> - /// The error. - /// </summary> - Error, - - /// <summary> - /// The debug. - /// </summary> - Debug, - - /// <summary> - /// Trace Level Logging. - /// </summary> - Trace, - } -} diff --git a/win/CS/HandBrakeWPF/Services/Logging/Model/LogMessage.cs b/win/CS/HandBrakeWPF/Services/Logging/Model/LogMessage.cs index 7fa98d1d2..51e5a1cb6 100644 --- a/win/CS/HandBrakeWPF/Services/Logging/Model/LogMessage.cs +++ b/win/CS/HandBrakeWPF/Services/Logging/Model/LogMessage.cs @@ -20,20 +20,12 @@ namespace HandBrakeWPF.Services.Logging.Model /// <param name="content"> /// The content. /// </param> - /// <param name="messageType"> - /// The message type. - /// </param> - /// <param name="logLevel"> - /// The log level. - /// </param> /// <param name="messageIndex"> /// The message Index. /// </param> - public LogMessage(string content, LogMessageType messageType, LogLevel logLevel, long messageIndex) + public LogMessage(string content, long messageIndex) { this.Content = content; - this.MessageType = messageType; - this.LogLevel = logLevel; this.MessageIndex = messageIndex; } @@ -43,17 +35,6 @@ namespace HandBrakeWPF.Services.Logging.Model public string Content { get; private set; } /// <summary> - /// Gets a value indicating whether this message was generated by the GUI. - /// If false, it was provided by libhb. - /// </summary> - public HandBrakeWPF.Services.Logging.Model.LogMessageType MessageType { get; private set; } - - /// <summary> - /// Gets the log level. - /// </summary> - public HandBrakeWPF.Services.Logging.Model.LogLevel LogLevel { get; private set; } - - /// <summary> /// Gets the message index. /// </summary> public long MessageIndex { get; private set; } diff --git a/win/CS/HandBrakeWPF/Services/Logging/Model/LogMessageType.cs b/win/CS/HandBrakeWPF/Services/Logging/Model/LogMessageType.cs deleted file mode 100644 index 7c50267fb..000000000 --- a/win/CS/HandBrakeWPF/Services/Logging/Model/LogMessageType.cs +++ /dev/null @@ -1,22 +0,0 @@ -// -------------------------------------------------------------------------------------------------------------------- -// <copyright file="LogMessageType.cs" company="HandBrake Project (http://handbrake.fr)"> -// This file is part of the HandBrake source code - It may be used under the terms of the GNU General Public License. -// </copyright> -// <summary> -// The log message type. -// </summary> -// -------------------------------------------------------------------------------------------------------------------- - -namespace HandBrakeWPF.Services.Logging.Model -{ - /// <summary> - /// The log message type. - /// </summary> - public enum LogMessageType - { - ScanOrEncode, - API, - Progress, - Application, - } -} diff --git a/win/CS/HandBrakeWPF/Services/PrePostActionService.cs b/win/CS/HandBrakeWPF/Services/PrePostActionService.cs index 67b5cf263..57be5051e 100644 --- a/win/CS/HandBrakeWPF/Services/PrePostActionService.cs +++ b/win/CS/HandBrakeWPF/Services/PrePostActionService.cs @@ -39,34 +39,23 @@ namespace HandBrakeWPF.Services /// </summary>
public class PrePostActionService : IPrePostActionService
{
- private readonly ILog log = LogService.GetLogger();
+ private readonly ILog log;
private readonly IQueueService queueProcessor;
private readonly IUserSettingService userSettingService;
private readonly IWindowManager windowManager;
private readonly IScan scanService;
- /// <summary>
- /// Initializes a new instance of the <see cref="PrePostActionService"/> class.
- /// </summary>
- /// <param name="queueProcessor">
- /// The queue processor.
- /// </param>
- /// <param name="userSettingService">
- /// The user Setting Service.
- /// </param>
- /// <param name="windowManager">
- /// The window Manager.
- /// </param>
- public PrePostActionService(IQueueService queueProcessor, IUserSettingService userSettingService, IWindowManager windowManager, IScan scanService)
+ public PrePostActionService(IQueueService queueProcessor, IUserSettingService userSettingService, IWindowManager windowManager, IScan scanService, ILog logService)
{
+ this.log = logService;
this.queueProcessor = queueProcessor;
this.userSettingService = userSettingService;
this.windowManager = windowManager;
this.scanService = scanService;
- this.queueProcessor.QueueCompleted += QueueProcessorQueueCompleted;
- this.queueProcessor.EncodeService.EncodeCompleted += EncodeService_EncodeCompleted;
- this.queueProcessor.EncodeService.EncodeStarted += EncodeService_EncodeStarted;
+ this.queueProcessor.QueueCompleted += this.QueueProcessorQueueCompleted;
+ this.queueProcessor.EncodeService.EncodeCompleted += this.EncodeService_EncodeCompleted;
+ this.queueProcessor.EncodeService.EncodeStarted += this.EncodeService_EncodeStarted;
}
/// <summary>
@@ -236,7 +225,7 @@ namespace HandBrakeWPF.Services private void ServiceLogMessage(string message)
{
- this.log.LogMessage(string.Format("# {1}{0}", Environment.NewLine, message), LogMessageType.ScanOrEncode, LogLevel.Info);
+ this.log.LogMessage(string.Format("# {1}{0}", Environment.NewLine, message));
}
}
}
diff --git a/win/CS/HandBrakeWPF/Services/Presets/PresetService.cs b/win/CS/HandBrakeWPF/Services/Presets/PresetService.cs index 9a46afc2b..8b4a1ba68 100644 --- a/win/CS/HandBrakeWPF/Services/Presets/PresetService.cs +++ b/win/CS/HandBrakeWPF/Services/Presets/PresetService.cs @@ -56,19 +56,11 @@ namespace HandBrakeWPF.Services.Presets private readonly List<Preset> flatPresetList = new List<Preset>();
private readonly IErrorService errorService;
private readonly IUserSettingService userSettingService;
- private ILog log = LogService.GetLogger();
+ private ILog log = null;
- /// <summary>
- /// Initializes a new instance of the <see cref="PresetService"/> class.
- /// </summary>
- /// <param name="errorService">
- /// The error service.
- /// </param>
- /// <param name="userSettingService">
- /// The User setting service.
- /// </param>
- public PresetService(IErrorService errorService, IUserSettingService userSettingService)
+ public PresetService(IErrorService errorService, IUserSettingService userSettingService, ILog logService)
{
+ this.log = logService;
this.errorService = errorService;
this.userSettingService = userSettingService;
}
@@ -917,7 +909,7 @@ namespace HandBrakeWPF.Services.Presets protected void ServiceLogMessage(string message)
{
- this.log.LogMessage(string.Format("Preset Service: {0}{1}{0}", Environment.NewLine, message), LogMessageType.Application, LogLevel.Info);
+ this.log.LogMessage(string.Format("Preset Service: {0}{1}{0}", Environment.NewLine, message));
}
}
}
\ No newline at end of file diff --git a/win/CS/HandBrakeWPF/Services/Queue/QueueService.cs b/win/CS/HandBrakeWPF/Services/Queue/QueueService.cs index bd5bb5960..cf7f642c2 100644 --- a/win/CS/HandBrakeWPF/Services/Queue/QueueService.cs +++ b/win/CS/HandBrakeWPF/Services/Queue/QueueService.cs @@ -28,6 +28,7 @@ namespace HandBrakeWPF.Services.Queue using HandBrakeWPF.Services.Encode.Factories; using HandBrakeWPF.Services.Encode.Model; using HandBrakeWPF.Services.Interfaces; + using HandBrakeWPF.Services.Logging.Interfaces; using HandBrakeWPF.Services.Queue.Model; using HandBrakeWPF.Utilities; @@ -37,8 +38,6 @@ namespace HandBrakeWPF.Services.Queue using Execute = Caliburn.Micro.Execute; using GeneralApplicationException = HandBrakeWPF.Exceptions.GeneralApplicationException; using IEncode = HandBrakeWPF.Services.Encode.Interfaces.IEncode; - using LogLevel = HandBrakeWPF.Services.Logging.Model.LogLevel; - using LogMessageType = HandBrakeWPF.Services.Logging.Model.LogMessageType; using LogService = HandBrakeWPF.Services.Logging.LogService; using QueueCompletedEventArgs = HandBrakeWPF.EventArgs.QueueCompletedEventArgs; using QueueProgressEventArgs = HandBrakeWPF.EventArgs.QueueProgressEventArgs; @@ -47,13 +46,15 @@ namespace HandBrakeWPF.Services.Queue { private static readonly object QueueLock = new object(); private readonly IUserSettingService userSettingService; + private readonly ILog logService; private readonly ObservableCollection<QueueTask> queue = new ObservableCollection<QueueTask>(); private readonly string queueFile; private bool clearCompleted; - public QueueService(IEncode encodeService, IUserSettingService userSettingService) + public QueueService(IEncode encodeService, IUserSettingService userSettingService, ILog logService) { this.userSettingService = userSettingService; + this.logService = logService; this.EncodeService = encodeService; // If this is the first instance, just use the main queue file, otherwise add the instance id to the filename. @@ -492,7 +493,7 @@ namespace HandBrakeWPF.Services.Queue { if (this.userSettingService.GetUserSetting<bool>(UserSettingConstants.PauseOnLowDiskspace) && !DriveUtilities.HasMinimumDiskSpace(job.Task.Destination, this.userSettingService.GetUserSetting<long>(UserSettingConstants.PauseQueueOnLowDiskspaceLevel))) { - LogService.GetLogger().LogMessage(Resources.PauseOnLowDiskspace, LogMessageType.ScanOrEncode, LogLevel.Info); + this.logService.LogMessage(Resources.PauseOnLowDiskspace); job.Status = QueueItemStatus.Waiting; this.Pause(); this.BackupQueue(string.Empty); diff --git a/win/CS/HandBrakeWPF/Services/Scan/LibScan.cs b/win/CS/HandBrakeWPF/Services/Scan/LibScan.cs index e69f9aee4..67f33ebbd 100644 --- a/win/CS/HandBrakeWPF/Services/Scan/LibScan.cs +++ b/win/CS/HandBrakeWPF/Services/Scan/LibScan.cs @@ -31,8 +31,6 @@ namespace HandBrakeWPF.Services.Scan using HandBrakeWPF.Utilities; using ILog = Logging.Interfaces.ILog; - using LogLevel = Logging.Model.LogLevel; - using LogMessageType = Logging.Model.LogMessageType; using LogService = Logging.LogService; using ScanProgressEventArgs = HandBrake.Interop.Interop.EventArgs.ScanProgressEventArgs; using Title = Model.Title; @@ -44,7 +42,7 @@ namespace HandBrakeWPF.Services.Scan { #region Private Variables - private readonly ILog log = LogService.GetLogger(); + private readonly ILog log = null; private TitleFactory titleFactory = new TitleFactory(); private string currentSourceScanPath; private IHandBrakeInstance instance; @@ -53,11 +51,9 @@ namespace HandBrakeWPF.Services.Scan #endregion - /// <summary> - /// Initializes a new instance of the <see cref="LibScan"/> class. - /// </summary> - public LibScan() + public LibScan(ILog logService) { + this.log = logService; this.IsScanning = false; } @@ -240,7 +236,7 @@ namespace HandBrakeWPF.Services.Scan /// </param> protected void ServiceLogMessage(string message) { - this.log.LogMessage(string.Format("{0} # {1}{0}", Environment.NewLine, message), LogMessageType.ScanOrEncode, LogLevel.Info); + this.log.LogMessage(string.Format("{0} # {1}{0}", Environment.NewLine, message)); } /// <summary> diff --git a/win/CS/HandBrakeWPF/Services/SystemService.cs b/win/CS/HandBrakeWPF/Services/SystemService.cs index 4bbc89f94..587a82128 100644 --- a/win/CS/HandBrakeWPF/Services/SystemService.cs +++ b/win/CS/HandBrakeWPF/Services/SystemService.cs @@ -28,7 +28,7 @@ namespace HandBrakeWPF.Services { private readonly IUserSettingService userSettingService; private readonly IEncode encodeService; - private readonly ILog log = LogService.GetLogger(); + private readonly ILog log = null; private Timer pollTimer; private bool criticalStateHit = false; @@ -36,8 +36,9 @@ namespace HandBrakeWPF.Services private bool lowPowerPause = false; private bool storageLowPause = false; - public SystemService(IUserSettingService userSettingService, IEncode encodeService) + public SystemService(IUserSettingService userSettingService, IEncode encodeService, ILog logService) { + this.log = logService; this.userSettingService = userSettingService; this.encodeService = encodeService; } @@ -71,12 +72,10 @@ namespace HandBrakeWPF.Services long lowLevel = this.userSettingService.GetUserSetting<long>(UserSettingConstants.PauseEncodeOnLowDiskspaceLevel); if (!this.storageLowPause && this.userSettingService.GetUserSetting<bool>(UserSettingConstants.PauseOnLowDiskspace) && !DriveUtilities.HasMinimumDiskSpace(directory, lowLevel)) { - LogService.GetLogger().LogMessage( + this.log.LogMessage( string.Format( Resources.SystemService_LowDiskSpaceLog, - lowLevel / 1000 / 1000 / 1000), - LogMessageType.Application, - LogLevel.Info); + lowLevel / 1000 / 1000 / 1000)); this.encodeService.Pause(); this.storageLowPause = true; } @@ -137,7 +136,7 @@ namespace HandBrakeWPF.Services private void ServiceLogMessage(string message) { - this.log.LogMessage(string.Format("{0}# {1}{0}", Environment.NewLine, message), LogMessageType.Application, LogLevel.Info); + this.log.LogMessage(string.Format("{0}# {1}{0}", Environment.NewLine, message)); } } } diff --git a/win/CS/HandBrakeWPF/Startup/AppBootstrapper.cs b/win/CS/HandBrakeWPF/Startup/AppBootstrapper.cs index bc4613278..67c7bd261 100644 --- a/win/CS/HandBrakeWPF/Startup/AppBootstrapper.cs +++ b/win/CS/HandBrakeWPF/Startup/AppBootstrapper.cs @@ -19,6 +19,7 @@ namespace HandBrakeWPF.Startup using HandBrakeWPF.Services;
using HandBrakeWPF.Services.Interfaces;
+ using HandBrakeWPF.Services.Logging;
using HandBrakeWPF.Services.Presets;
using HandBrakeWPF.Services.Presets.Interfaces;
using HandBrakeWPF.Services.Queue;
@@ -64,6 +65,7 @@ namespace HandBrakeWPF.Startup this.container.Singleton<IUserSettingService, UserSettingService>();
this.container.Singleton<IPresetService, PresetService>();
this.container.Singleton<IQueueService, QueueService>();
+ this.container.Singleton<HandBrakeWPF.Services.Logging.Interfaces.ILog, LogService>();
// Commands
diff --git a/win/CS/HandBrakeWPF/ViewModels/LogViewModel.cs b/win/CS/HandBrakeWPF/ViewModels/LogViewModel.cs index b37939f36..0e8d5ab6a 100644 --- a/win/CS/HandBrakeWPF/ViewModels/LogViewModel.cs +++ b/win/CS/HandBrakeWPF/ViewModels/LogViewModel.cs @@ -33,21 +33,14 @@ namespace HandBrakeWPF.ViewModels {
private readonly IErrorService errorService;
- #region Private Fields
-
private readonly ILog logService;
private StringBuilder log = new StringBuilder();
private long lastReadIndex;
- #endregion
-
- /// <summary>
- /// Initializes a new instance of the <see cref="LogViewModel"/> class.
- /// </summary>
- public LogViewModel(IErrorService errorService)
+ public LogViewModel(IErrorService errorService, ILog logService)
{
this.errorService = errorService;
- this.logService = LogService.GetLogger();
+ this.logService = logService;
this.Title = Resources.LogViewModel_Title;
}
diff --git a/win/CS/HandBrakeWPF/ViewModels/StaticPreviewViewModel.cs b/win/CS/HandBrakeWPF/ViewModels/StaticPreviewViewModel.cs index 8608ea259..9cc5c70df 100644 --- a/win/CS/HandBrakeWPF/ViewModels/StaticPreviewViewModel.cs +++ b/win/CS/HandBrakeWPF/ViewModels/StaticPreviewViewModel.cs @@ -27,6 +27,7 @@ namespace HandBrakeWPF.ViewModels using HandBrakeWPF.Properties;
using HandBrakeWPF.Services.Encode.Model.Models;
using HandBrakeWPF.Services.Interfaces;
+ using HandBrakeWPF.Services.Logging.Interfaces;
using HandBrakeWPF.Services.Queue.Model;
using HandBrakeWPF.Services.Scan.Interfaces;
using HandBrakeWPF.Services.Scan.Model;
@@ -63,7 +64,7 @@ namespace HandBrakeWPF.ViewModels #region Constructors and Destructors
- public StaticPreviewViewModel(IScan scanService, IUserSettingService userSettingService, IErrorService errorService, IHbFunctionsProvider hbFunctionsProvider)
+ public StaticPreviewViewModel(IScan scanService, IUserSettingService userSettingService, IErrorService errorService, IHbFunctionsProvider hbFunctionsProvider, ILog logService)
{
this.scanService = scanService;
this.selectedPreviewImage = 1;
@@ -73,7 +74,7 @@ namespace HandBrakeWPF.ViewModels // Live Preview
this.userSettingService = userSettingService;
this.errorService = errorService;
- this.encodeService = new LibEncode(hbFunctionsProvider); // Preview needs a separate instance rather than the shared singleton. This could maybe do with being refactored at some point
+ this.encodeService = new LibEncode(hbFunctionsProvider, logService); // Preview needs a separate instance rather than the shared singleton. This could maybe do with being refactored at some point
this.Title = "Preview";
this.Percentage = "0.00%";
|