diff --git a/Emby.Server.Implementations/ApplicationHost.cs b/Emby.Server.Implementations/ApplicationHost.cs index 318f7d912..b8506eb86 100644 --- a/Emby.Server.Implementations/ApplicationHost.cs +++ b/Emby.Server.Implementations/ApplicationHost.cs @@ -1795,9 +1795,6 @@ namespace Emby.Server.Implementations // Include composable parts in the Photos assembly list.Add(GetAssembly(typeof(PhotoProvider))); - // Common implementations - list.Add(GetAssembly(typeof(TaskManager))); - // Emby.Server implementations list.Add(GetAssembly(typeof(InstallationManager))); diff --git a/Emby.Server.Implementations/Emby.Server.Implementations.csproj b/Emby.Server.Implementations/Emby.Server.Implementations.csproj index 891d9cfc4..89b9325a2 100644 --- a/Emby.Server.Implementations/Emby.Server.Implementations.csproj +++ b/Emby.Server.Implementations/Emby.Server.Implementations.csproj @@ -434,8 +434,7 @@ - - + @@ -671,12 +670,6 @@ ..\packages\MediaBrowser.Naming.1.0.5\lib\portable-net45+win8\MediaBrowser.Naming.dll True - - ..\packages\Microsoft.IO.RecyclableMemoryStream.1.2.2\lib\net45\Microsoft.IO.RecyclableMemoryStream.dll - - - ..\packages\NLog.4.4.12\lib\net45\NLog.dll - ..\packages\ServiceStack.Text.4.5.8\lib\net45\ServiceStack.Text.dll True diff --git a/Emby.Server.Implementations/IO/MemoryStreamProvider.cs b/Emby.Server.Implementations/IO/MemoryStreamProvider.cs index eca76203c..e9ecb7e44 100644 --- a/Emby.Server.Implementations/IO/MemoryStreamProvider.cs +++ b/Emby.Server.Implementations/IO/MemoryStreamProvider.cs @@ -1,35 +1,8 @@ using System.IO; using MediaBrowser.Model.IO; -using Microsoft.IO; namespace Emby.Server.Implementations.IO { - public class RecyclableMemoryStreamProvider : IMemoryStreamFactory - { - readonly RecyclableMemoryStreamManager _manager = new RecyclableMemoryStreamManager(); - - public MemoryStream CreateNew() - { - return _manager.GetStream(); - } - - public MemoryStream CreateNew(int capacity) - { - return _manager.GetStream("RecyclableMemoryStream", capacity); - } - - public MemoryStream CreateNew(byte[] buffer) - { - return _manager.GetStream("RecyclableMemoryStream", buffer, 0, buffer.Length); - } - - public bool TryGetBuffer(MemoryStream stream, out byte[] buffer) - { - buffer = stream.GetBuffer(); - return true; - } - } - public class MemoryStreamProvider : IMemoryStreamFactory { public MemoryStream CreateNew() diff --git a/Emby.Server.Implementations/Logging/NLogger.cs b/Emby.Server.Implementations/Logging/NLogger.cs deleted file mode 100644 index c380a640f..000000000 --- a/Emby.Server.Implementations/Logging/NLogger.cs +++ /dev/null @@ -1,224 +0,0 @@ -using System; -using System.Text; -using MediaBrowser.Model.Logging; - -namespace Emby.Server.Implementations.Logging -{ - /// - /// Class NLogger - /// - public class NLogger : ILogger - { - /// - /// The _logger - /// - private readonly NLog.Logger _logger; - - private readonly ILogManager _logManager; - - /// - /// The _lock object - /// - private static readonly object LockObject = new object(); - - /// - /// Initializes a new instance of the class. - /// - /// The name. - /// The log manager. - public NLogger(string name, ILogManager logManager) - { - _logManager = logManager; - lock (LockObject) - { - _logger = NLog.LogManager.GetLogger(name); - } - } - - /// - /// Infoes the specified message. - /// - /// The message. - /// The param list. - public void Info(string message, params object[] paramList) - { - _logger.Info(message, paramList); - } - - /// - /// Errors the specified message. - /// - /// The message. - /// The param list. - public void Error(string message, params object[] paramList) - { - _logger.Error(message, paramList); - } - - /// - /// Warns the specified message. - /// - /// The message. - /// The param list. - public void Warn(string message, params object[] paramList) - { - _logger.Warn(message, paramList); - } - - /// - /// Debugs the specified message. - /// - /// The message. - /// The param list. - public void Debug(string message, params object[] paramList) - { - if (_logManager.LogSeverity == LogSeverity.Info) - { - return; - } - - _logger.Debug(message, paramList); - } - - /// - /// Logs the exception. - /// - /// The message. - /// The exception. - /// The param list. - /// - public void ErrorException(string message, Exception exception, params object[] paramList) - { - LogException(LogSeverity.Error, message, exception, paramList); - } - - /// - /// Logs the exception. - /// - /// The level. - /// The message. - /// The exception. - /// The param list. - private void LogException(LogSeverity level, string message, Exception exception, params object[] paramList) - { - message = FormatMessage(message, paramList).Replace(Environment.NewLine, ". "); - - var messageText = LogHelper.GetLogMessage(exception); - - var prefix = _logManager.ExceptionMessagePrefix; - - if (!string.IsNullOrWhiteSpace(prefix)) - { - messageText.Insert(0, prefix); - } - - LogMultiline(message, level, messageText); - } - - /// - /// Formats the message. - /// - /// The message. - /// The param list. - /// System.String. - private static string FormatMessage(string message, params object[] paramList) - { - if (paramList != null) - { - for (var i = 0; i < paramList.Length; i++) - { - var obj = paramList[i]; - - message = message.Replace("{" + i + "}", (obj == null ? "null" : obj.ToString())); - } - } - - return message; - } - - /// - /// Logs the multiline. - /// - /// The message. - /// The severity. - /// Content of the additional. - public void LogMultiline(string message, LogSeverity severity, StringBuilder additionalContent) - { - if (severity == LogSeverity.Debug && _logManager.LogSeverity == LogSeverity.Info) - { - return; - } - - additionalContent.Insert(0, message + Environment.NewLine); - - const char tabChar = '\t'; - - var text = additionalContent.ToString() - .Replace(Environment.NewLine, Environment.NewLine + tabChar) - .TrimEnd(tabChar); - - if (text.EndsWith(Environment.NewLine)) - { - text = text.Substring(0, text.LastIndexOf(Environment.NewLine, StringComparison.OrdinalIgnoreCase)); - } - - _logger.Log(GetLogLevel(severity), text); - } - - /// - /// Gets the log level. - /// - /// The severity. - /// NLog.LogLevel. - private NLog.LogLevel GetLogLevel(LogSeverity severity) - { - switch (severity) - { - case LogSeverity.Debug: - return NLog.LogLevel.Debug; - case LogSeverity.Error: - return NLog.LogLevel.Error; - case LogSeverity.Warn: - return NLog.LogLevel.Warn; - case LogSeverity.Fatal: - return NLog.LogLevel.Fatal; - case LogSeverity.Info: - return NLog.LogLevel.Info; - default: - throw new ArgumentException("Unknown LogSeverity: " + severity.ToString()); - } - } - - /// - /// Logs the specified severity. - /// - /// The severity. - /// The message. - /// The param list. - public void Log(LogSeverity severity, string message, params object[] paramList) - { - _logger.Log(GetLogLevel(severity), message, paramList); - } - - /// - /// Fatals the specified message. - /// - /// The message. - /// The param list. - public void Fatal(string message, params object[] paramList) - { - _logger.Fatal(message, paramList); - } - - /// - /// Fatals the exception. - /// - /// The message. - /// The exception. - /// The param list. - public void FatalException(string message, Exception exception, params object[] paramList) - { - LogException(LogSeverity.Fatal, message, exception, paramList); - } - } -} diff --git a/Emby.Server.Implementations/Logging/NlogManager.cs b/Emby.Server.Implementations/Logging/NlogManager.cs deleted file mode 100644 index 77f8d0297..000000000 --- a/Emby.Server.Implementations/Logging/NlogManager.cs +++ /dev/null @@ -1,553 +0,0 @@ -using System; -using System.IO; -using System.Linq; -using MediaBrowser.Model.Logging; -using NLog; -using NLog.Config; -using NLog.Filters; -using NLog.Targets; -using NLog.Targets.Wrappers; - -namespace Emby.Server.Implementations.Logging -{ - /// - /// Class NlogManager - /// - public class NlogManager : ILogManager - { - #region Private Fields - - private LogSeverity _severity = LogSeverity.Debug; - - /// - /// Gets or sets the log directory. - /// - /// The log directory. - private readonly string LogDirectory; - - /// - /// Gets or sets the log file prefix. - /// - /// The log file prefix. - private readonly string LogFilePrefix; - - #endregion - - #region Event Declarations - - /// - /// Occurs when [logger loaded]. - /// - public event EventHandler LoggerLoaded; - - #endregion - - #region Public Properties - - /// - /// Gets the log file path. - /// - /// The log file path. - public string LogFilePath { get; private set; } - - /// - /// Gets or sets the exception message prefix. - /// - /// The exception message prefix. - public string ExceptionMessagePrefix { get; set; } - - public string NLogConfigurationFilePath { get; set; } - - public LogSeverity LogSeverity - { - - get - { - return _severity; - } - - set - { - DebugFileWriter( - LogDirectory, String.Format( - "SET LogSeverity, _severity = [{0}], value = [{1}]", - _severity.ToString(), - value.ToString() - )); - - var changed = _severity != value; - - _severity = value; - - if (changed) - { - UpdateLogLevel(value); - } - - } - } - - #endregion - - #region Constructor(s) - - /// - /// Initializes a new instance of the class. - /// - /// The log directory. - /// The log file name prefix. - public NlogManager(string logDirectory, string logFileNamePrefix) - { - DebugFileWriter( - logDirectory, String.Format( - "NlogManager constructor called, logDirectory is [{0}], logFileNamePrefix is [{1}], _severity is [{2}].", - logDirectory, - logFileNamePrefix, - _severity.ToString() - )); - - LogDirectory = logDirectory; - LogFilePrefix = logFileNamePrefix; - - LogManager.Configuration = new LoggingConfiguration(); - } - - /// - /// Initializes a new instance of the class. - /// - /// The log directory. - /// The log file name prefix. - public NlogManager(string logDirectory, string logFileNamePrefix, LogSeverity initialSeverity) : this(logDirectory, logFileNamePrefix) - { - _severity = initialSeverity; - - DebugFileWriter( - logDirectory, String.Format( - "NlogManager constructor called, logDirectory is [{0}], logFileNamePrefix is [{1}], _severity is [{2}].", - logDirectory, - logFileNamePrefix, - _severity.ToString() - )); - } - - #endregion - - #region Private Methods - - /// - /// Adds the file target. - /// - /// The path. - /// The level. - private void AddFileTarget(string path, LogSeverity level) - { - - DebugFileWriter( - LogDirectory, String.Format( - "AddFileTarget called, path = [{0}], level = [{1}].", - path, - level.ToString() - )); - - RemoveTarget("ApplicationLogFileWrapper"); - - // https://github.com/NLog/NLog/wiki/Performance - var wrapper = new AsyncTargetWrapper - { - OverflowAction = AsyncTargetWrapperOverflowAction.Block, - QueueLimit = 10000, - BatchSize = 500, - TimeToSleepBetweenBatches = 50 - }; - - wrapper.Name = "ApplicationLogFileWrapper"; - - var logFile = new FileTarget - { - FileName = path, - Layout = "${longdate} ${level} ${logger}: ${message}", - KeepFileOpen = true, - ConcurrentWrites = false - }; - - logFile.Name = "ApplicationLogFile"; - - wrapper.WrappedTarget = logFile; - - AddLogTarget(wrapper, level); - - } - - /// - /// Gets the log level. - /// - /// The severity. - /// LogLevel. - /// Unrecognized LogSeverity - private LogLevel GetLogLevel(LogSeverity severity) - { - switch (severity) - { - case LogSeverity.Debug: - return LogLevel.Debug; - case LogSeverity.Error: - return LogLevel.Error; - case LogSeverity.Fatal: - return LogLevel.Fatal; - case LogSeverity.Info: - return LogLevel.Info; - case LogSeverity.Warn: - return LogLevel.Warn; - default: - throw new ArgumentException("Unrecognized LogSeverity"); - } - } - - private void UpdateLogLevel(LogSeverity newLevel) - { - DebugFileWriter( - LogDirectory, String.Format( - "UpdateLogLevel called, newLevel = [{0}].", - newLevel.ToString() - )); - - var level = GetLogLevel(newLevel); - - var rules = LogManager.Configuration.LoggingRules; - - foreach (var rule in rules) - { - if (!rule.IsLoggingEnabledForLevel(level)) - { - rule.EnableLoggingForLevel(level); - } - foreach (var lev in rule.Levels.ToArray()) - { - if (lev < level) - { - rule.DisableLoggingForLevel(lev); - } - } - } - } - - private void AddCustomFilters(string defaultLoggerNamePattern, LoggingRule defaultRule) - { - DebugFileWriter( - LogDirectory, String.Format( - "AddCustomFilters called, defaultLoggerNamePattern = [{0}], defaultRule.LoggerNamePattern = [{1}].", - defaultLoggerNamePattern, - defaultRule.LoggerNamePattern - )); - - try - { - var customConfig = new NLog.Config.XmlLoggingConfiguration(NLogConfigurationFilePath); - - DebugFileWriter( - LogDirectory, String.Format( - "Custom Configuration Loaded, Rule Count = [{0}].", - customConfig.LoggingRules.Count.ToString() - )); - - foreach (var customRule in customConfig.LoggingRules) - { - - DebugFileWriter( - LogDirectory, String.Format( - "Read Custom Rule, LoggerNamePattern = [{0}], Targets = [{1}].", - customRule.LoggerNamePattern, - string.Join(",", customRule.Targets.Select(x => x.Name).ToList()) - )); - - if (customRule.LoggerNamePattern.Equals(defaultLoggerNamePattern)) - { - - if (customRule.Targets.Any((arg) => arg.Name.Equals(defaultRule.Targets.First().Name))) - { - - DebugFileWriter( - LogDirectory, String.Format( - "Custom rule filters can be applied to this target, Filter Count = [{0}].", - customRule.Filters.Count.ToString() - )); - - foreach (ConditionBasedFilter customFilter in customRule.Filters) - { - - DebugFileWriter( - LogDirectory, String.Format( - "Read Custom Filter, Filter = [{0}], Action = [{1}], Type = [{2}].", - customFilter.Condition.ToString(), - customFilter.Action.ToString(), - customFilter.GetType().ToString() - )); - - defaultRule.Filters.Add(customFilter); - - } - } - else - { - - DebugFileWriter( - LogDirectory, String.Format( - "Ignoring custom rule as [Target] does not match." - )); - - } - - } - else - { - - DebugFileWriter( - LogDirectory, String.Format( - "Ignoring custom rule as [LoggerNamePattern] does not match." - )); - - } - } - } - catch (Exception ex) - { - // Intentionally do nothing, prevent issues affecting normal execution. - DebugFileWriter( - LogDirectory, String.Format( - "Exception in AddCustomFilters, ex.Message = [{0}].", - ex.Message - ) - ); - - } - } - - #endregion - - #region Public Methods - - /// - /// Gets the logger. - /// - /// The name. - /// ILogger. - public MediaBrowser.Model.Logging.ILogger GetLogger(string name) - { - - DebugFileWriter( - LogDirectory, String.Format( - "GetLogger called, name = [{0}].", - name - )); - - return new NLogger(name, this); - - } - - /// - /// Adds the log target. - /// - /// The target. - /// The level. - public void AddLogTarget(Target target, LogSeverity level) - { - - DebugFileWriter( - LogDirectory, String.Format( - "AddLogTarget called, target.Name = [{0}], level = [{1}].", - target.Name, - level.ToString() - )); - - string loggerNamePattern = "*"; - var config = LogManager.Configuration; - var rule = new LoggingRule(loggerNamePattern, GetLogLevel(level), target); - - config.AddTarget(target.Name, target); - - AddCustomFilters(loggerNamePattern, rule); - - config.LoggingRules.Add(rule); - - LogManager.Configuration = config; - - } - - /// - /// Removes the target. - /// - /// The name. - public void RemoveTarget(string name) - { - - DebugFileWriter( - LogDirectory, String.Format( - "RemoveTarget called, name = [{0}].", - name - )); - - var config = LogManager.Configuration; - - var target = config.FindTargetByName(name); - - if (target != null) - { - foreach (var rule in config.LoggingRules.ToList()) - { - var contains = rule.Targets.Contains(target); - - rule.Targets.Remove(target); - - if (contains) - { - config.LoggingRules.Remove(rule); - } - } - - config.RemoveTarget(name); - LogManager.Configuration = config; - } - } - - public void AddConsoleOutput() - { - - DebugFileWriter( - LogDirectory, String.Format( - "AddConsoleOutput called." - )); - - RemoveTarget("ConsoleTargetWrapper"); - - var wrapper = new AsyncTargetWrapper(); - wrapper.Name = "ConsoleTargetWrapper"; - - var target = new ConsoleTarget() - { - Layout = "${level}, ${logger}, ${message}", - Error = false - }; - - target.Name = "ConsoleTarget"; - - wrapper.WrappedTarget = target; - - AddLogTarget(wrapper, LogSeverity); - - } - - public void RemoveConsoleOutput() - { - - DebugFileWriter( - LogDirectory, String.Format( - "RemoveConsoleOutput called." - )); - - RemoveTarget("ConsoleTargetWrapper"); - - } - - /// - /// Reloads the logger, maintaining the current log level. - /// - public void ReloadLogger() - { - ReloadLogger(LogSeverity); - } - - /// - /// Reloads the logger, using the specified logging level. - /// - /// The level. - public void ReloadLogger(LogSeverity level) - { - - DebugFileWriter( - LogDirectory, String.Format( - "ReloadLogger called, level = [{0}], LogFilePath (existing) = [{1}].", - level.ToString(), - LogFilePath - )); - - LogFilePath = Path.Combine(LogDirectory, LogFilePrefix + "-" + decimal.Floor(DateTime.Now.Ticks / 10000000) + ".txt"); - - Directory.CreateDirectory(Path.GetDirectoryName(LogFilePath)); - - AddFileTarget(LogFilePath, level); - - LogSeverity = level; - - if (LoggerLoaded != null) - { - try - { - - DebugFileWriter( - LogDirectory, String.Format( - "ReloadLogger called, raised event LoggerLoaded." - )); - - LoggerLoaded(this, EventArgs.Empty); - - } - catch (Exception ex) - { - GetLogger("Logger").ErrorException("Error in LoggerLoaded event", ex); - } - } - } - - /// - /// Flushes this instance. - /// - public void Flush() - { - - DebugFileWriter( - LogDirectory, String.Format( - "Flush called." - )); - - LogManager.Flush(); - - } - - #endregion - - #region Conditional Debug Methods - - /// - /// DEBUG: Standalone method to write out debug to assist with logger development/troubleshooting. - /// - /// The output file will be written to the server's log directory. - /// Calls to the method are safe and will never throw any exceptions. - /// Method calls will be omitted unless the library is compiled with DEBUG defined. - /// - /// - private static void DebugFileWriter(string logDirectory, string message) - { -#if DEBUG - try - { - - System.IO.File.AppendAllText( - Path.Combine(logDirectory, "NlogManager.txt"), - String.Format( - "{0} : {1}{2}", - System.DateTime.UtcNow.ToString("yyyy-MM-ddTHH:mm:ss.fffZ"), - message, - System.Environment.NewLine - ) - ); - - } - catch (Exception ex) - { - // Intentionally do nothing, prevent issues affecting normal execution. - } -#endif - } - #endregion - } -} \ No newline at end of file diff --git a/Emby.Server.Implementations/Logging/SimpleLogManager.cs b/Emby.Server.Implementations/Logging/SimpleLogManager.cs new file mode 100644 index 000000000..1a50f162a --- /dev/null +++ b/Emby.Server.Implementations/Logging/SimpleLogManager.cs @@ -0,0 +1,301 @@ +using System; +using System.Collections.Concurrent; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Text; +using System.Threading; +using System.Threading.Tasks; +using MediaBrowser.Model.Logging; + +namespace Emby.Server.Implementations.Logging +{ + public class SimpleLogManager : ILogManager, IDisposable + { + public LogSeverity LogSeverity { get; set; } + public string ExceptionMessagePrefix { get; set; } + private FileLogger _fileLogger; + + private readonly string LogDirectory; + private readonly string LogFilePrefix; + public string DateTimeFormat = "yyyy-MM-dd HH:mm:ss.fff"; + + public SimpleLogManager(string logDirectory, string logFileNamePrefix) + { + LogDirectory = logDirectory; + LogFilePrefix = logFileNamePrefix; + } + + public ILogger GetLogger(string name) + { + return new NamedLogger(name, this); + } + + public void ReloadLogger(LogSeverity severity) + { + LogSeverity = severity; + + var logger = _fileLogger; + if (logger != null) + { + logger.Dispose(); + } + + var path = Path.Combine(LogDirectory, LogFilePrefix + "-" + decimal.Floor(DateTime.Now.Ticks / 10000000) + ".txt"); + + _fileLogger = new FileLogger(path); + + if (LoggerLoaded != null) + { + try + { + + LoggerLoaded(this, EventArgs.Empty); + + } + catch (Exception ex) + { + GetLogger("Logger").ErrorException("Error in LoggerLoaded event", ex); + } + } + } + + public event EventHandler LoggerLoaded; + + public void Flush() + { + var logger = _fileLogger; + if (logger != null) + { + logger.Flush(); + } + } + + private bool _console = true; + public void AddConsoleOutput() + { + _console = true; + } + + public void RemoveConsoleOutput() + { + _console = false; + } + + public void Log(string message) + { + if (_console) + { + Console.WriteLine(message); + } + + var logger = _fileLogger; + if (logger != null) + { + message = DateTime.Now.ToString(DateTimeFormat) + " " + message; + + logger.Log(message); + } + } + + public void Dispose() + { + var logger = _fileLogger; + if (logger != null) + { + logger.Dispose(); + } + + _fileLogger = null; + } + } + + public class FileLogger : IDisposable + { + private readonly Stream _fileStream; + + private bool _disposed; + private readonly CancellationTokenSource _cancellationTokenSource; + private readonly BlockingCollection _queue = new BlockingCollection(); + + public FileLogger(string path) + { + Directory.CreateDirectory(Path.GetDirectoryName(path)); + + _fileStream = new FileStream(path, FileMode.Create, FileAccess.Write, FileShare.Read); + _cancellationTokenSource = new CancellationTokenSource(); + + Task.Factory.StartNew(LogInternal, _cancellationTokenSource.Token, TaskCreationOptions.LongRunning, TaskScheduler.Default); + } + + private void LogInternal() + { + while (!_cancellationTokenSource.IsCancellationRequested) + { + try + { + var any = false; + + foreach (var message in _queue.GetConsumingEnumerable()) + { + any = true; + + var bytes = Encoding.UTF8.GetBytes(message + Environment.NewLine); + _fileStream.Write(bytes, 0, bytes.Length); + } + + if (any) + { + _fileStream.Flush(); + } + } + catch + { + + } + } + } + + public void Log(string message) + { + if (_disposed) + { + return; + } + + _queue.Add(message); + } + + public void Flush() + { + if (_disposed) + { + return; + } + + _fileStream.Flush(); + } + + public void Dispose() + { + _cancellationTokenSource.Cancel(); + + _disposed = true; + + _fileStream.Flush(); + _fileStream.Dispose(); + } + } + + public class NamedLogger : ILogger + { + public string Name { get; private set; } + private readonly SimpleLogManager _logManager; + + public NamedLogger(string name, SimpleLogManager logManager) + { + Name = name; + _logManager = logManager; + } + + public void Info(string message, params object[] paramList) + { + Log(LogSeverity.Info, message, paramList); + } + + public void Error(string message, params object[] paramList) + { + Log(LogSeverity.Error, message, paramList); + } + + public void Warn(string message, params object[] paramList) + { + Log(LogSeverity.Warn, message, paramList); + } + + public void Debug(string message, params object[] paramList) + { + if (_logManager.LogSeverity == LogSeverity.Info) + { + return; + } + Log(LogSeverity.Debug, message, paramList); + } + + public void Fatal(string message, params object[] paramList) + { + Log(LogSeverity.Fatal, message, paramList); + } + + public void FatalException(string message, Exception exception, params object[] paramList) + { + ErrorException(message, exception, paramList); + } + + public void ErrorException(string message, Exception exception, params object[] paramList) + { + LogException(LogSeverity.Error, message, exception, paramList); + } + + private void LogException(LogSeverity level, string message, Exception exception, params object[] paramList) + { + message = FormatMessage(message, paramList).Replace(Environment.NewLine, ". "); + + var messageText = LogHelper.GetLogMessage(exception); + + var prefix = _logManager.ExceptionMessagePrefix; + + if (!string.IsNullOrWhiteSpace(prefix)) + { + messageText.Insert(0, prefix); + } + + LogMultiline(message, level, messageText); + } + + private static string FormatMessage(string message, params object[] paramList) + { + if (paramList != null) + { + for (var i = 0; i < paramList.Length; i++) + { + var obj = paramList[i]; + + message = message.Replace("{" + i + "}", (obj == null ? "null" : obj.ToString())); + } + } + + return message; + } + + public void LogMultiline(string message, LogSeverity severity, StringBuilder additionalContent) + { + if (severity == LogSeverity.Debug && _logManager.LogSeverity == LogSeverity.Info) + { + return; + } + + additionalContent.Insert(0, message + Environment.NewLine); + + const char tabChar = '\t'; + + var text = additionalContent.ToString() + .Replace(Environment.NewLine, Environment.NewLine + tabChar) + .TrimEnd(tabChar); + + if (text.EndsWith(Environment.NewLine)) + { + text = text.Substring(0, text.LastIndexOf(Environment.NewLine, StringComparison.OrdinalIgnoreCase)); + } + + Log(severity, text); + } + + public void Log(LogSeverity severity, string message, params object[] paramList) + { + message = severity + " " + Name + ": " + FormatMessage(message, paramList); + + _logManager.Log(message); + } + } +} diff --git a/Emby.Server.Implementations/packages.config b/Emby.Server.Implementations/packages.config index fc28b2653..0933cd5e4 100644 --- a/Emby.Server.Implementations/packages.config +++ b/Emby.Server.Implementations/packages.config @@ -2,8 +2,6 @@ - - diff --git a/MediaBrowser.Model/Logging/ILogManager.cs b/MediaBrowser.Model/Logging/ILogManager.cs index 59bb86756..218f13eb4 100644 --- a/MediaBrowser.Model/Logging/ILogManager.cs +++ b/MediaBrowser.Model/Logging/ILogManager.cs @@ -31,12 +31,6 @@ namespace MediaBrowser.Model.Logging /// void ReloadLogger(LogSeverity severity); - /// - /// Gets the log file path. - /// - /// The log file path. - string LogFilePath { get; } - /// /// Occurs when [logger loaded]. /// diff --git a/MediaBrowser.Server.Mono/MediaBrowser.Server.Mono.csproj b/MediaBrowser.Server.Mono/MediaBrowser.Server.Mono.csproj index bb113bf03..a0b1d526a 100644 --- a/MediaBrowser.Server.Mono/MediaBrowser.Server.Mono.csproj +++ b/MediaBrowser.Server.Mono/MediaBrowser.Server.Mono.csproj @@ -51,9 +51,6 @@ False ..\packages\Mono.Posix.4.0.0.0\lib\net40\Mono.Posix.dll - - ..\packages\NLog.4.4.12\lib\net45\NLog.dll - ..\packages\ServiceStack.Text.4.5.8\lib\net45\ServiceStack.Text.dll True diff --git a/MediaBrowser.Server.Mono/packages.config b/MediaBrowser.Server.Mono/packages.config index c77327e22..525a0098c 100644 --- a/MediaBrowser.Server.Mono/packages.config +++ b/MediaBrowser.Server.Mono/packages.config @@ -1,7 +1,6 @@  - diff --git a/MediaBrowser.ServerApplication/MainStartup.cs b/MediaBrowser.ServerApplication/MainStartup.cs index 7f72473ea..169ac2eef 100644 --- a/MediaBrowser.ServerApplication/MainStartup.cs +++ b/MediaBrowser.ServerApplication/MainStartup.cs @@ -73,7 +73,7 @@ namespace MediaBrowser.ServerApplication var appPaths = CreateApplicationPaths(ApplicationPath, IsRunningAsService); - var logManager = new NlogManager(appPaths.LogDirectoryPath, "server"); + var logManager = new SimpleLogManager(appPaths.LogDirectoryPath, "server"); logManager.ReloadLogger(LogSeverity.Debug); logManager.AddConsoleOutput(); diff --git a/MediaBrowser.ServerApplication/MediaBrowser.ServerApplication.csproj b/MediaBrowser.ServerApplication/MediaBrowser.ServerApplication.csproj index 41015a98b..cb7c92a88 100644 --- a/MediaBrowser.ServerApplication/MediaBrowser.ServerApplication.csproj +++ b/MediaBrowser.ServerApplication/MediaBrowser.ServerApplication.csproj @@ -73,9 +73,6 @@ ..\ThirdParty\emby\Emby.Server.Sync.dll - - ..\packages\NLog.4.4.12\lib\net45\NLog.dll - ..\packages\ServiceStack.Text.4.5.8\lib\net45\ServiceStack.Text.dll True diff --git a/MediaBrowser.ServerApplication/packages.config b/MediaBrowser.ServerApplication/packages.config index ed953e299..3af1bcf4d 100644 --- a/MediaBrowser.ServerApplication/packages.config +++ b/MediaBrowser.ServerApplication/packages.config @@ -1,6 +1,5 @@  -