remove unused libs

This commit is contained in:
Luke Pulverenti 2017-08-16 11:42:36 -04:00
parent bfcd1b520f
commit 56263a9fa2
13 changed files with 303 additions and 832 deletions

View File

@ -1795,9 +1795,6 @@ namespace Emby.Server.Implementations
// Include composable parts in the Photos assembly // Include composable parts in the Photos assembly
list.Add(GetAssembly(typeof(PhotoProvider))); list.Add(GetAssembly(typeof(PhotoProvider)));
// Common implementations
list.Add(GetAssembly(typeof(TaskManager)));
// Emby.Server implementations // Emby.Server implementations
list.Add(GetAssembly(typeof(InstallationManager))); list.Add(GetAssembly(typeof(InstallationManager)));

View File

@ -434,8 +434,7 @@
<Compile Include="Localization\LocalizationManager.cs" /> <Compile Include="Localization\LocalizationManager.cs" />
<Compile Include="Localization\TextLocalizer.cs" /> <Compile Include="Localization\TextLocalizer.cs" />
<Compile Include="Logging\ConsoleLogger.cs" /> <Compile Include="Logging\ConsoleLogger.cs" />
<Compile Include="Logging\NLogger.cs" /> <Compile Include="Logging\SimpleLogManager.cs" />
<Compile Include="Logging\NlogManager.cs" />
<Compile Include="Logging\UnhandledExceptionWriter.cs" /> <Compile Include="Logging\UnhandledExceptionWriter.cs" />
<Compile Include="MediaEncoder\EncodingManager.cs" /> <Compile Include="MediaEncoder\EncodingManager.cs" />
<Compile Include="Migrations\IVersionMigration.cs" /> <Compile Include="Migrations\IVersionMigration.cs" />
@ -671,12 +670,6 @@
<HintPath>..\packages\MediaBrowser.Naming.1.0.5\lib\portable-net45+win8\MediaBrowser.Naming.dll</HintPath> <HintPath>..\packages\MediaBrowser.Naming.1.0.5\lib\portable-net45+win8\MediaBrowser.Naming.dll</HintPath>
<Private>True</Private> <Private>True</Private>
</Reference> </Reference>
<Reference Include="Microsoft.IO.RecyclableMemoryStream, Version=1.2.2.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>..\packages\Microsoft.IO.RecyclableMemoryStream.1.2.2\lib\net45\Microsoft.IO.RecyclableMemoryStream.dll</HintPath>
</Reference>
<Reference Include="NLog, Version=4.0.0.0, Culture=neutral, PublicKeyToken=5120e14c03d0593c, processorArchitecture=MSIL">
<HintPath>..\packages\NLog.4.4.12\lib\net45\NLog.dll</HintPath>
</Reference>
<Reference Include="ServiceStack.Text, Version=4.5.8.0, Culture=neutral, processorArchitecture=MSIL"> <Reference Include="ServiceStack.Text, Version=4.5.8.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\ServiceStack.Text.4.5.8\lib\net45\ServiceStack.Text.dll</HintPath> <HintPath>..\packages\ServiceStack.Text.4.5.8\lib\net45\ServiceStack.Text.dll</HintPath>
<Private>True</Private> <Private>True</Private>

View File

@ -1,35 +1,8 @@
using System.IO; using System.IO;
using MediaBrowser.Model.IO; using MediaBrowser.Model.IO;
using Microsoft.IO;
namespace Emby.Server.Implementations.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 class MemoryStreamProvider : IMemoryStreamFactory
{ {
public MemoryStream CreateNew() public MemoryStream CreateNew()

View File

@ -1,224 +0,0 @@
using System;
using System.Text;
using MediaBrowser.Model.Logging;
namespace Emby.Server.Implementations.Logging
{
/// <summary>
/// Class NLogger
/// </summary>
public class NLogger : ILogger
{
/// <summary>
/// The _logger
/// </summary>
private readonly NLog.Logger _logger;
private readonly ILogManager _logManager;
/// <summary>
/// The _lock object
/// </summary>
private static readonly object LockObject = new object();
/// <summary>
/// Initializes a new instance of the <see cref="NLogger" /> class.
/// </summary>
/// <param name="name">The name.</param>
/// <param name="logManager">The log manager.</param>
public NLogger(string name, ILogManager logManager)
{
_logManager = logManager;
lock (LockObject)
{
_logger = NLog.LogManager.GetLogger(name);
}
}
/// <summary>
/// Infoes the specified message.
/// </summary>
/// <param name="message">The message.</param>
/// <param name="paramList">The param list.</param>
public void Info(string message, params object[] paramList)
{
_logger.Info(message, paramList);
}
/// <summary>
/// Errors the specified message.
/// </summary>
/// <param name="message">The message.</param>
/// <param name="paramList">The param list.</param>
public void Error(string message, params object[] paramList)
{
_logger.Error(message, paramList);
}
/// <summary>
/// Warns the specified message.
/// </summary>
/// <param name="message">The message.</param>
/// <param name="paramList">The param list.</param>
public void Warn(string message, params object[] paramList)
{
_logger.Warn(message, paramList);
}
/// <summary>
/// Debugs the specified message.
/// </summary>
/// <param name="message">The message.</param>
/// <param name="paramList">The param list.</param>
public void Debug(string message, params object[] paramList)
{
if (_logManager.LogSeverity == LogSeverity.Info)
{
return;
}
_logger.Debug(message, paramList);
}
/// <summary>
/// Logs the exception.
/// </summary>
/// <param name="message">The message.</param>
/// <param name="exception">The exception.</param>
/// <param name="paramList">The param list.</param>
/// <exception cref="System.NotImplementedException"></exception>
public void ErrorException(string message, Exception exception, params object[] paramList)
{
LogException(LogSeverity.Error, message, exception, paramList);
}
/// <summary>
/// Logs the exception.
/// </summary>
/// <param name="level">The level.</param>
/// <param name="message">The message.</param>
/// <param name="exception">The exception.</param>
/// <param name="paramList">The param list.</param>
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);
}
/// <summary>
/// Formats the message.
/// </summary>
/// <param name="message">The message.</param>
/// <param name="paramList">The param list.</param>
/// <returns>System.String.</returns>
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;
}
/// <summary>
/// Logs the multiline.
/// </summary>
/// <param name="message">The message.</param>
/// <param name="severity">The severity.</param>
/// <param name="additionalContent">Content of the additional.</param>
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);
}
/// <summary>
/// Gets the log level.
/// </summary>
/// <param name="severity">The severity.</param>
/// <returns>NLog.LogLevel.</returns>
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());
}
}
/// <summary>
/// Logs the specified severity.
/// </summary>
/// <param name="severity">The severity.</param>
/// <param name="message">The message.</param>
/// <param name="paramList">The param list.</param>
public void Log(LogSeverity severity, string message, params object[] paramList)
{
_logger.Log(GetLogLevel(severity), message, paramList);
}
/// <summary>
/// Fatals the specified message.
/// </summary>
/// <param name="message">The message.</param>
/// <param name="paramList">The param list.</param>
public void Fatal(string message, params object[] paramList)
{
_logger.Fatal(message, paramList);
}
/// <summary>
/// Fatals the exception.
/// </summary>
/// <param name="message">The message.</param>
/// <param name="exception">The exception.</param>
/// <param name="paramList">The param list.</param>
public void FatalException(string message, Exception exception, params object[] paramList)
{
LogException(LogSeverity.Fatal, message, exception, paramList);
}
}
}

View File

@ -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
{
/// <summary>
/// Class NlogManager
/// </summary>
public class NlogManager : ILogManager
{
#region Private Fields
private LogSeverity _severity = LogSeverity.Debug;
/// <summary>
/// Gets or sets the log directory.
/// </summary>
/// <value>The log directory.</value>
private readonly string LogDirectory;
/// <summary>
/// Gets or sets the log file prefix.
/// </summary>
/// <value>The log file prefix.</value>
private readonly string LogFilePrefix;
#endregion
#region Event Declarations
/// <summary>
/// Occurs when [logger loaded].
/// </summary>
public event EventHandler LoggerLoaded;
#endregion
#region Public Properties
/// <summary>
/// Gets the log file path.
/// </summary>
/// <value>The log file path.</value>
public string LogFilePath { get; private set; }
/// <summary>
/// Gets or sets the exception message prefix.
/// </summary>
/// <value>The exception message prefix.</value>
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)
/// <summary>
/// Initializes a new instance of the <see cref="NlogManager" /> class.
/// </summary>
/// <param name="logDirectory">The log directory.</param>
/// <param name="logFileNamePrefix">The log file name prefix.</param>
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();
}
/// <summary>
/// Initializes a new instance of the <see cref="NlogManager" /> class.
/// </summary>
/// <param name="logDirectory">The log directory.</param>
/// <param name="logFileNamePrefix">The log file name prefix.</param>
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
/// <summary>
/// Adds the file target.
/// </summary>
/// <param name="path">The path.</param>
/// <param name="level">The level.</param>
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);
}
/// <summary>
/// Gets the log level.
/// </summary>
/// <param name="severity">The severity.</param>
/// <returns>LogLevel.</returns>
/// <exception cref="System.ArgumentException">Unrecognized LogSeverity</exception>
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
/// <summary>
/// Gets the logger.
/// </summary>
/// <param name="name">The name.</param>
/// <returns>ILogger.</returns>
public MediaBrowser.Model.Logging.ILogger GetLogger(string name)
{
DebugFileWriter(
LogDirectory, String.Format(
"GetLogger called, name = [{0}].",
name
));
return new NLogger(name, this);
}
/// <summary>
/// Adds the log target.
/// </summary>
/// <param name="target">The target.</param>
/// <param name="level">The level.</param>
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;
}
/// <summary>
/// Removes the target.
/// </summary>
/// <param name="name">The name.</param>
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");
}
/// <summary>
/// Reloads the logger, maintaining the current log level.
/// </summary>
public void ReloadLogger()
{
ReloadLogger(LogSeverity);
}
/// <summary>
/// Reloads the logger, using the specified logging level.
/// </summary>
/// <param name="level">The level.</param>
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);
}
}
}
/// <summary>
/// Flushes this instance.
/// </summary>
public void Flush()
{
DebugFileWriter(
LogDirectory, String.Format(
"Flush called."
));
LogManager.Flush();
}
#endregion
#region Conditional Debug Methods
/// <summary>
/// DEBUG: Standalone method to write out debug to assist with logger development/troubleshooting.
/// <list type="bullet">
/// <item><description>The output file will be written to the server's log directory.</description></item>
/// <item><description>Calls to the method are safe and will never throw any exceptions.</description></item>
/// <item><description>Method calls will be omitted unless the library is compiled with DEBUG defined.</description></item>
/// </list>
/// </summary>
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
}
}

View File

@ -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<string> _queue = new BlockingCollection<string>();
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);
}
}
}

View File

@ -2,8 +2,6 @@
<packages> <packages>
<package id="Emby.XmlTv" version="1.0.9" targetFramework="net46" /> <package id="Emby.XmlTv" version="1.0.9" targetFramework="net46" />
<package id="MediaBrowser.Naming" version="1.0.5" targetFramework="portable45-net45+win8" /> <package id="MediaBrowser.Naming" version="1.0.5" targetFramework="portable45-net45+win8" />
<package id="Microsoft.IO.RecyclableMemoryStream" version="1.2.2" targetFramework="net46" />
<package id="NLog" version="4.4.12" targetFramework="net46" />
<package id="ServiceStack.Text" version="4.5.8" targetFramework="net46" /> <package id="ServiceStack.Text" version="4.5.8" targetFramework="net46" />
<package id="SharpCompress" version="0.14.0" targetFramework="net46" /> <package id="SharpCompress" version="0.14.0" targetFramework="net46" />
<package id="SimpleInjector" version="4.0.8" targetFramework="net46" /> <package id="SimpleInjector" version="4.0.8" targetFramework="net46" />

View File

@ -31,12 +31,6 @@ namespace MediaBrowser.Model.Logging
/// </summary> /// </summary>
void ReloadLogger(LogSeverity severity); void ReloadLogger(LogSeverity severity);
/// <summary>
/// Gets the log file path.
/// </summary>
/// <value>The log file path.</value>
string LogFilePath { get; }
/// <summary> /// <summary>
/// Occurs when [logger loaded]. /// Occurs when [logger loaded].
/// </summary> /// </summary>

View File

@ -51,9 +51,6 @@
<SpecificVersion>False</SpecificVersion> <SpecificVersion>False</SpecificVersion>
<HintPath>..\packages\Mono.Posix.4.0.0.0\lib\net40\Mono.Posix.dll</HintPath> <HintPath>..\packages\Mono.Posix.4.0.0.0\lib\net40\Mono.Posix.dll</HintPath>
</Reference> </Reference>
<Reference Include="NLog, Version=4.0.0.0, Culture=neutral, PublicKeyToken=5120e14c03d0593c, processorArchitecture=MSIL">
<HintPath>..\packages\NLog.4.4.12\lib\net45\NLog.dll</HintPath>
</Reference>
<Reference Include="ServiceStack.Text, Version=4.5.8.0, Culture=neutral, processorArchitecture=MSIL"> <Reference Include="ServiceStack.Text, Version=4.5.8.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\ServiceStack.Text.4.5.8\lib\net45\ServiceStack.Text.dll</HintPath> <HintPath>..\packages\ServiceStack.Text.4.5.8\lib\net45\ServiceStack.Text.dll</HintPath>
<Private>True</Private> <Private>True</Private>

View File

@ -1,7 +1,6 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<packages> <packages>
<package id="Mono.Posix" version="4.0.0.0" targetFramework="net45" /> <package id="Mono.Posix" version="4.0.0.0" targetFramework="net45" />
<package id="NLog" version="4.4.12" targetFramework="net46" />
<package id="ServiceStack.Text" version="4.5.8" targetFramework="net46" /> <package id="ServiceStack.Text" version="4.5.8" targetFramework="net46" />
<package id="SharpCompress" version="0.14.0" targetFramework="net46" /> <package id="SharpCompress" version="0.14.0" targetFramework="net46" />
<package id="SimpleInjector" version="4.0.8" targetFramework="net46" /> <package id="SimpleInjector" version="4.0.8" targetFramework="net46" />

View File

@ -73,7 +73,7 @@ namespace MediaBrowser.ServerApplication
var appPaths = CreateApplicationPaths(ApplicationPath, IsRunningAsService); var appPaths = CreateApplicationPaths(ApplicationPath, IsRunningAsService);
var logManager = new NlogManager(appPaths.LogDirectoryPath, "server"); var logManager = new SimpleLogManager(appPaths.LogDirectoryPath, "server");
logManager.ReloadLogger(LogSeverity.Debug); logManager.ReloadLogger(LogSeverity.Debug);
logManager.AddConsoleOutput(); logManager.AddConsoleOutput();

View File

@ -73,9 +73,6 @@
<Reference Include="Emby.Server.Sync"> <Reference Include="Emby.Server.Sync">
<HintPath>..\ThirdParty\emby\Emby.Server.Sync.dll</HintPath> <HintPath>..\ThirdParty\emby\Emby.Server.Sync.dll</HintPath>
</Reference> </Reference>
<Reference Include="NLog, Version=4.0.0.0, Culture=neutral, PublicKeyToken=5120e14c03d0593c, processorArchitecture=MSIL">
<HintPath>..\packages\NLog.4.4.12\lib\net45\NLog.dll</HintPath>
</Reference>
<Reference Include="ServiceStack.Text, Version=4.5.8.0, Culture=neutral, processorArchitecture=MSIL"> <Reference Include="ServiceStack.Text, Version=4.5.8.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\ServiceStack.Text.4.5.8\lib\net45\ServiceStack.Text.dll</HintPath> <HintPath>..\packages\ServiceStack.Text.4.5.8\lib\net45\ServiceStack.Text.dll</HintPath>
<Private>True</Private> <Private>True</Private>

View File

@ -1,6 +1,5 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<packages> <packages>
<package id="NLog" version="4.4.12" targetFramework="net462" />
<package id="ServiceStack.Text" version="4.5.8" targetFramework="net462" /> <package id="ServiceStack.Text" version="4.5.8" targetFramework="net462" />
<package id="SharpCompress" version="0.14.0" targetFramework="net462" /> <package id="SharpCompress" version="0.14.0" targetFramework="net462" />
<package id="SimpleInjector" version="4.0.8" targetFramework="net462" /> <package id="SimpleInjector" version="4.0.8" targetFramework="net462" />