aboutsummaryrefslogtreecommitdiff
path: root/MediaBrowser.Common/Net
diff options
context:
space:
mode:
Diffstat (limited to 'MediaBrowser.Common/Net')
-rw-r--r--MediaBrowser.Common/Net/AlchemyWebSocket.cs10
-rw-r--r--MediaBrowser.Common/Net/HttpServer.cs26
-rw-r--r--MediaBrowser.Common/Net/NativeWebSocket.cs18
-rw-r--r--MediaBrowser.Common/Net/WebSocketConnection.cs15
4 files changed, 46 insertions, 23 deletions
diff --git a/MediaBrowser.Common/Net/AlchemyWebSocket.cs b/MediaBrowser.Common/Net/AlchemyWebSocket.cs
index 1971990db..5a5103f74 100644
--- a/MediaBrowser.Common/Net/AlchemyWebSocket.cs
+++ b/MediaBrowser.Common/Net/AlchemyWebSocket.cs
@@ -17,7 +17,7 @@ namespace MediaBrowser.Common.Net
/// <summary>
/// The logger
/// </summary>
- private static ILogger Logger = LogManager.GetLogger("AlchemyWebSocket");
+ private readonly ILogger _logger;
/// <summary>
/// Gets or sets the web socket.
@@ -29,20 +29,22 @@ namespace MediaBrowser.Common.Net
/// Initializes a new instance of the <see cref="AlchemyWebSocket" /> class.
/// </summary>
/// <param name="context">The context.</param>
+ /// <param name="logger">The logger.</param>
/// <exception cref="System.ArgumentNullException">context</exception>
- public AlchemyWebSocket(UserContext context)
+ public AlchemyWebSocket(UserContext context, ILogger logger)
{
if (context == null)
{
throw new ArgumentNullException("context");
}
+ _logger = logger;
UserContext = context;
context.SetOnDisconnect(OnDisconnected);
context.SetOnReceive(OnReceive);
- Logger.Info("Client connected from {0}", context.ClientAddress);
+ _logger.Info("Client connected from {0}", context.ClientAddress);
}
/// <summary>
@@ -87,7 +89,7 @@ namespace MediaBrowser.Common.Net
}
catch (Exception ex)
{
- Logger.ErrorException("Error processing web socket message", ex);
+ _logger.ErrorException("Error processing web socket message", ex);
}
}
}
diff --git a/MediaBrowser.Common/Net/HttpServer.cs b/MediaBrowser.Common/Net/HttpServer.cs
index c09153064..7183b63c0 100644
--- a/MediaBrowser.Common/Net/HttpServer.cs
+++ b/MediaBrowser.Common/Net/HttpServer.cs
@@ -32,7 +32,7 @@ namespace MediaBrowser.Common.Net
/// <summary>
/// The logger
/// </summary>
- private static ILogger Logger = Logging.LogManager.GetLogger("HttpServer");
+ private readonly ILogger _logger;
/// <summary>
/// Gets the URL prefix.
@@ -69,17 +69,27 @@ namespace MediaBrowser.Common.Net
/// <param name="urlPrefix">The URL.</param>
/// <param name="serverName">Name of the product.</param>
/// <param name="kernel">The kernel.</param>
+ /// <param name="logger">The logger.</param>
/// <param name="defaultRedirectpath">The default redirectpath.</param>
/// <exception cref="System.ArgumentNullException">urlPrefix</exception>
- public HttpServer(string urlPrefix, string serverName, IKernel kernel, string defaultRedirectpath = null)
+ public HttpServer(string urlPrefix, string serverName, IKernel kernel, ILogger logger, string defaultRedirectpath = null)
: base()
{
if (string.IsNullOrEmpty(urlPrefix))
{
throw new ArgumentNullException("urlPrefix");
}
+ if (kernel == null)
+ {
+ throw new ArgumentNullException("kernel");
+ }
+ if (logger == null)
+ {
+ throw new ArgumentNullException("logger");
+ }
DefaultRedirectPath = defaultRedirectpath;
+ _logger = logger;
EndpointHostConfig.Instance.ServiceStackHandlerFactoryPath = null;
EndpointHostConfig.Instance.MetadataRedirectPath = "metadata";
@@ -274,12 +284,12 @@ namespace MediaBrowser.Common.Net
if (WebSocketConnected != null)
{
- WebSocketConnected(this, new WebSocketConnectEventArgs { WebSocket = new NativeWebSocket(webSocketContext.WebSocket), Endpoint = ctx.Request.RemoteEndPoint });
+ WebSocketConnected(this, new WebSocketConnectEventArgs { WebSocket = new NativeWebSocket(webSocketContext.WebSocket, _logger), Endpoint = ctx.Request.RemoteEndPoint });
}
}
catch (Exception ex)
{
- Logger.ErrorException("AcceptWebSocketAsync error", ex);
+ _logger.ErrorException("AcceptWebSocketAsync error", ex);
ctx.Response.StatusCode = 500;
ctx.Response.Close();
@@ -301,7 +311,7 @@ namespace MediaBrowser.Common.Net
if (Kernel.Configuration.EnableHttpLevelLogging)
{
- Logger.LogMultiline(type + " request received from " + ctx.Request.RemoteEndPoint, LogSeverity.Debug, log);
+ _logger.LogMultiline(type + " request received from " + ctx.Request.RemoteEndPoint, LogSeverity.Debug, log);
}
}
@@ -313,7 +323,7 @@ namespace MediaBrowser.Common.Net
/// <param name="statusCode">The status code.</param>
private void HandleException(HttpListenerResponse response, Exception ex, int statusCode)
{
- Logger.ErrorException("Error processing request", ex);
+ _logger.ErrorException("Error processing request", ex);
response.StatusCode = statusCode;
@@ -352,7 +362,7 @@ namespace MediaBrowser.Common.Net
}
catch (Exception errorEx)
{
- Logger.ErrorException("Error processing failed request", errorEx);
+ _logger.ErrorException("Error processing failed request", errorEx);
}
}
@@ -408,7 +418,7 @@ namespace MediaBrowser.Common.Net
if (Kernel.Configuration.EnableHttpLevelLogging)
{
- Logger.LogMultiline(msg, LogSeverity.Debug, log);
+ _logger.LogMultiline(msg, LogSeverity.Debug, log);
}
}
diff --git a/MediaBrowser.Common/Net/NativeWebSocket.cs b/MediaBrowser.Common/Net/NativeWebSocket.cs
index d57deca54..23f3d4be3 100644
--- a/MediaBrowser.Common/Net/NativeWebSocket.cs
+++ b/MediaBrowser.Common/Net/NativeWebSocket.cs
@@ -1,5 +1,4 @@
-using MediaBrowser.Common.Logging;
-using MediaBrowser.Common.Serialization;
+using MediaBrowser.Common.Serialization;
using MediaBrowser.Model.Logging;
using System;
using System.IO;
@@ -17,7 +16,7 @@ namespace MediaBrowser.Common.Net
/// <summary>
/// The logger
/// </summary>
- private static ILogger Logger = LogManager.GetLogger("NativeWebSocket");
+ private readonly ILogger _logger;
/// <summary>
/// Gets or sets the web socket.
@@ -29,14 +28,21 @@ namespace MediaBrowser.Common.Net
/// Initializes a new instance of the <see cref="NativeWebSocket" /> class.
/// </summary>
/// <param name="socket">The socket.</param>
+ /// <param name="logger">The logger.</param>
/// <exception cref="System.ArgumentNullException">socket</exception>
- public NativeWebSocket(WebSocket socket)
+ public NativeWebSocket(WebSocket socket, ILogger logger)
{
if (socket == null)
{
throw new ArgumentNullException("socket");
}
+ if (logger == null)
+ {
+ throw new ArgumentNullException("logger");
+ }
+
+ _logger = logger;
WebSocket = socket;
Receive();
@@ -66,7 +72,7 @@ namespace MediaBrowser.Common.Net
}
catch (WebSocketException ex)
{
- Logger.ErrorException("Error reveiving web socket message", ex);
+ _logger.ErrorException("Error reveiving web socket message", ex);
break;
}
@@ -83,7 +89,7 @@ namespace MediaBrowser.Common.Net
}
catch (Exception ex)
{
- Logger.ErrorException("Error processing web socket message", ex);
+ _logger.ErrorException("Error processing web socket message", ex);
}
}
}
diff --git a/MediaBrowser.Common/Net/WebSocketConnection.cs b/MediaBrowser.Common/Net/WebSocketConnection.cs
index ca12d07be..24b8e2a9f 100644
--- a/MediaBrowser.Common/Net/WebSocketConnection.cs
+++ b/MediaBrowser.Common/Net/WebSocketConnection.cs
@@ -37,7 +37,7 @@ namespace MediaBrowser.Common.Net
/// <summary>
/// The logger
/// </summary>
- private static readonly ILogger Logger = LogManager.GetLogger("WebSocketConnection");
+ private readonly ILogger _logger;
/// <summary>
/// Initializes a new instance of the <see cref="WebSocketConnection" /> class.
@@ -46,7 +46,7 @@ namespace MediaBrowser.Common.Net
/// <param name="remoteEndPoint">The remote end point.</param>
/// <param name="receiveAction">The receive action.</param>
/// <exception cref="System.ArgumentNullException">socket</exception>
- public WebSocketConnection(IWebSocket socket, EndPoint remoteEndPoint, Action<WebSocketMessageInfo> receiveAction)
+ public WebSocketConnection(IWebSocket socket, EndPoint remoteEndPoint, Action<WebSocketMessageInfo> receiveAction, ILogger logger)
{
if (socket == null)
{
@@ -60,10 +60,15 @@ namespace MediaBrowser.Common.Net
{
throw new ArgumentNullException("receiveAction");
}
+ if (logger == null)
+ {
+ throw new ArgumentNullException("logger");
+ }
_socket = socket;
_socket.OnReceiveDelegate = info => OnReceive(info, receiveAction);
RemoteEndPoint = remoteEndPoint;
+ _logger = logger;
}
/// <summary>
@@ -81,7 +86,7 @@ namespace MediaBrowser.Common.Net
}
catch (Exception ex)
{
- Logger.ErrorException("Error processing web socket message", ex);
+ _logger.ErrorException("Error processing web socket message", ex);
}
}
@@ -148,13 +153,13 @@ namespace MediaBrowser.Common.Net
}
catch (OperationCanceledException)
{
- Logger.Info("WebSocket message to {0} was cancelled", RemoteEndPoint);
+ _logger.Info("WebSocket message to {0} was cancelled", RemoteEndPoint);
throw;
}
catch (Exception ex)
{
- Logger.ErrorException("Error sending WebSocket message {0}", ex, RemoteEndPoint);
+ _logger.ErrorException("Error sending WebSocket message {0}", ex, RemoteEndPoint);
throw;
}