aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLuke Pulverenti <luke.pulverenti@gmail.com>2014-01-08 23:44:51 -0500
committerLuke Pulverenti <luke.pulverenti@gmail.com>2014-01-08 23:44:51 -0500
commit247a40fa614241b52babb29bc03b0afd9a9031f9 (patch)
tree5e82b401988d9246d8da2e59a9e29d0c2627c743
parentdcc5f9ebab9fe0260d6886d79284ccdce83a4814 (diff)
add console logging during startup
-rw-r--r--MediaBrowser.Common.Implementations/Logging/NlogManager.cs23
-rw-r--r--MediaBrowser.Common/Net/IServerManager.cs4
-rw-r--r--MediaBrowser.Controller/IServerApplicationHost.cs6
-rw-r--r--MediaBrowser.Controller/Net/IHttpServer.cs6
-rw-r--r--MediaBrowser.Model/Logging/ILogManager.cs10
-rw-r--r--MediaBrowser.Mono.userprefs3
-rw-r--r--MediaBrowser.Providers/ImagesByName/ImageUtils.cs3
-rw-r--r--MediaBrowser.Server.Implementations/HttpServer/HttpListenerHost.cs37
-rw-r--r--MediaBrowser.Server.Implementations/ServerManager/ServerManager.cs14
-rw-r--r--MediaBrowser.Server.Mono/Program.cs1
-rw-r--r--MediaBrowser.ServerApplication/ApplicationHost.cs21
-rw-r--r--MediaBrowser.ServerApplication/MainStartup.cs1
12 files changed, 79 insertions, 50 deletions
diff --git a/MediaBrowser.Common.Implementations/Logging/NlogManager.cs b/MediaBrowser.Common.Implementations/Logging/NlogManager.cs
index fb7fd1698..40dc380ea 100644
--- a/MediaBrowser.Common.Implementations/Logging/NlogManager.cs
+++ b/MediaBrowser.Common.Implementations/Logging/NlogManager.cs
@@ -187,7 +187,7 @@ namespace MediaBrowser.Common.Implementations.Logging
LogFilePath = Path.Combine(LogDirectory, LogFilePrefix + "-" + decimal.Round(DateTime.Now.Ticks / 10000000) + ".log");
Directory.CreateDirectory(Path.GetDirectoryName(LogFilePath));
-
+
AddFileTarget(LogFilePath, level);
LogSeverity = level;
@@ -212,5 +212,26 @@ namespace MediaBrowser.Common.Implementations.Logging
{
LogManager.Flush();
}
+
+
+ public void AddConsoleOutput()
+ {
+ var target = new ConsoleTarget()
+ {
+ Layout = "${level}, ${logger}, ${message}",
+ Error = false
+ };
+
+ RemoveTarget("ConsoleTarget");
+
+ target.Name = "ConsoleTarget";
+
+ AddLogTarget(target, LogSeverity);
+ }
+
+ public void RemoveConsoleOutput()
+ {
+ RemoveTarget("ConsoleTarget");
+ }
}
}
diff --git a/MediaBrowser.Common/Net/IServerManager.cs b/MediaBrowser.Common/Net/IServerManager.cs
index 6965677bb..f81c99ac6 100644
--- a/MediaBrowser.Common/Net/IServerManager.cs
+++ b/MediaBrowser.Common/Net/IServerManager.cs
@@ -25,9 +25,9 @@ namespace MediaBrowser.Common.Net
/// <summary>
/// Starts this instance.
/// </summary>
- /// <param name="urlPrefix">The URL prefix.</param>
+ /// <param name="urlPrefixes">The URL prefixes.</param>
/// <param name="enableHttpLogging">if set to <c>true</c> [enable HTTP logging].</param>
- void Start(string urlPrefix, bool enableHttpLogging);
+ void Start(IEnumerable<string> urlPrefixes, bool enableHttpLogging);
/// <summary>
/// Starts the web socket server.
diff --git a/MediaBrowser.Controller/IServerApplicationHost.cs b/MediaBrowser.Controller/IServerApplicationHost.cs
index f3312d2cb..5554ced37 100644
--- a/MediaBrowser.Controller/IServerApplicationHost.cs
+++ b/MediaBrowser.Controller/IServerApplicationHost.cs
@@ -21,12 +21,6 @@ namespace MediaBrowser.Controller
string WebApplicationName { get; }
/// <summary>
- /// Gets the HTTP server URL prefix.
- /// </summary>
- /// <value>The HTTP server URL prefix.</value>
- string HttpServerUrlPrefix { get; }
-
- /// <summary>
/// Gets a value indicating whether [supports automatic run at startup].
/// </summary>
/// <value><c>true</c> if [supports automatic run at startup]; otherwise, <c>false</c>.</value>
diff --git a/MediaBrowser.Controller/Net/IHttpServer.cs b/MediaBrowser.Controller/Net/IHttpServer.cs
index ba2cd0ccc..20f07c74d 100644
--- a/MediaBrowser.Controller/Net/IHttpServer.cs
+++ b/MediaBrowser.Controller/Net/IHttpServer.cs
@@ -13,13 +13,13 @@ namespace MediaBrowser.Controller.Net
/// Gets the URL prefix.
/// </summary>
/// <value>The URL prefix.</value>
- string UrlPrefix { get; }
+ IEnumerable<string> UrlPrefixes { get; }
/// <summary>
/// Starts the specified server name.
/// </summary>
- /// <param name="urlPrefix">The URL.</param>
- void StartServer(string urlPrefix);
+ /// <param name="urlPrefixes">The URL prefixes.</param>
+ void StartServer(IEnumerable<string> urlPrefixes);
/// <summary>
/// Gets a value indicating whether [supports web sockets].
diff --git a/MediaBrowser.Model/Logging/ILogManager.cs b/MediaBrowser.Model/Logging/ILogManager.cs
index fabca4459..674d8fd16 100644
--- a/MediaBrowser.Model/Logging/ILogManager.cs
+++ b/MediaBrowser.Model/Logging/ILogManager.cs
@@ -40,5 +40,15 @@ namespace MediaBrowser.Model.Logging
/// Flushes this instance.
/// </summary>
void Flush();
+
+ /// <summary>
+ /// Adds the console output.
+ /// </summary>
+ void AddConsoleOutput();
+
+ /// <summary>
+ /// Removes the console output.
+ /// </summary>
+ void RemoveConsoleOutput();
}
}
diff --git a/MediaBrowser.Mono.userprefs b/MediaBrowser.Mono.userprefs
index 3017cf969..da74b9ccd 100644
--- a/MediaBrowser.Mono.userprefs
+++ b/MediaBrowser.Mono.userprefs
@@ -1,10 +1,11 @@
<Properties>
<MonoDevelop.Ide.Workspace ActiveConfiguration="Release Mono" />
- <MonoDevelop.Ide.Workbench ActiveDocument="MediaBrowser.Server.Mono\Native\NativeApp.cs">
+ <MonoDevelop.Ide.Workbench ActiveDocument="MediaBrowser.Server.Mono\Program.cs">
<Files>
<File FileName="MediaBrowser.Server.Mono\app.config" Line="1" Column="1" />
<File FileName="MediaBrowser.ServerApplication\ApplicationHost.cs" Line="1" Column="1" />
<File FileName="MediaBrowser.Server.Mono\Native\NativeApp.cs" Line="12" Column="23" />
+ <File FileName="MediaBrowser.Server.Mono\Program.cs" Line="36" Column="34" />
</Files>
</MonoDevelop.Ide.Workbench>
<MonoDevelop.Ide.DebuggingService.Breakpoints>
diff --git a/MediaBrowser.Providers/ImagesByName/ImageUtils.cs b/MediaBrowser.Providers/ImagesByName/ImageUtils.cs
index 4301c7432..72df3697a 100644
--- a/MediaBrowser.Providers/ImagesByName/ImageUtils.cs
+++ b/MediaBrowser.Providers/ImagesByName/ImageUtils.cs
@@ -64,7 +64,8 @@ namespace MediaBrowser.Providers.ImagesByName
.Replace(".", string.Empty)
.Replace("&", string.Empty)
.Replace("!", string.Empty)
- .Replace(",", string.Empty);
+ .Replace(",", string.Empty)
+ .Replace("/", string.Empty);
}
public static IEnumerable<string> GetAvailableImages(string file)
diff --git a/MediaBrowser.Server.Implementations/HttpServer/HttpListenerHost.cs b/MediaBrowser.Server.Implementations/HttpServer/HttpListenerHost.cs
index 34d705bfb..e9a94c3ad 100644
--- a/MediaBrowser.Server.Implementations/HttpServer/HttpListenerHost.cs
+++ b/MediaBrowser.Server.Implementations/HttpServer/HttpListenerHost.cs
@@ -32,7 +32,7 @@ namespace MediaBrowser.Server.Implementations.HttpServer
private string DefaultRedirectPath { get; set; }
private readonly ILogger _logger;
- public string UrlPrefix { get; private set; }
+ public IEnumerable<string> UrlPrefixes { get; private set; }
private readonly List<IRestfulService> _restServices = new List<IRestfulService>();
@@ -66,7 +66,7 @@ namespace MediaBrowser.Server.Implementations.HttpServer
_containerAdapter = new ContainerAdapter(applicationHost);
- for (var i = 0; i < 2; i++)
+ for (var i = 0; i < 1; i++)
{
_autoResetEvents.Add(new AutoResetEvent(false));
}
@@ -145,20 +145,14 @@ namespace MediaBrowser.Server.Implementations.HttpServer
public override ServiceStackHost Start(string listeningAtUrlBase)
{
- StartListener(listeningAtUrlBase);
+ StartListener();
return this;
}
/// <summary>
/// Starts the Web Service
/// </summary>
- /// <param name="listeningAtUrlBase">
- /// A Uri that acts as the base that the server is listening on.
- /// Format should be: http://127.0.0.1:8080/ or http://127.0.0.1:8080/somevirtual/
- /// Note: the trailing slash is required! For more info see the
- /// HttpListener.Prefixes property on MSDN.
- /// </param>
- protected void StartListener(string listeningAtUrlBase)
+ private void StartListener()
{
// *** Already running - just leave it in place
if (IsStarted)
@@ -167,14 +161,13 @@ namespace MediaBrowser.Server.Implementations.HttpServer
if (Listener == null)
Listener = new HttpListener();
- HostContext.Config.HandlerFactoryPath = ListenerRequest.GetHandlerPathIfAny(listeningAtUrlBase);
+ HostContext.Config.HandlerFactoryPath = ListenerRequest.GetHandlerPathIfAny(UrlPrefixes.First());
- UrlPrefix = listeningAtUrlBase;
-
- Listener.Prefixes.Add(listeningAtUrlBase);
-
- _logger.Info("Adding HttpListener Prefixes");
- Listener.Prefixes.Add(listeningAtUrlBase);
+ foreach (var prefix in UrlPrefixes)
+ {
+ _logger.Info("Adding HttpListener prefix " + prefix);
+ Listener.Prefixes.Add(prefix);
+ }
IsStarted = true;
_logger.Info("Starting HttpListner");
@@ -419,7 +412,10 @@ namespace MediaBrowser.Server.Implementations.HttpServer
{
if (Listener != null)
{
- Listener.Prefixes.Remove(UrlPrefix);
+ foreach (var prefix in UrlPrefixes)
+ {
+ Listener.Prefixes.Remove(prefix);
+ }
Listener.Close();
}
@@ -516,9 +512,10 @@ namespace MediaBrowser.Server.Implementations.HttpServer
GC.SuppressFinalize(this);
}
- public void StartServer(string urlPrefix)
+ public void StartServer(IEnumerable<string> urlPrefixes)
{
- Start(urlPrefix);
+ UrlPrefixes = urlPrefixes.ToList();
+ Start(UrlPrefixes.First());
}
public bool SupportsWebSockets
diff --git a/MediaBrowser.Server.Implementations/ServerManager/ServerManager.cs b/MediaBrowser.Server.Implementations/ServerManager/ServerManager.cs
index a2dfb51d2..671312274 100644
--- a/MediaBrowser.Server.Implementations/ServerManager/ServerManager.cs
+++ b/MediaBrowser.Server.Implementations/ServerManager/ServerManager.cs
@@ -124,9 +124,9 @@ namespace MediaBrowser.Server.Implementations.ServerManager
/// <summary>
/// Starts this instance.
/// </summary>
- public void Start(string urlPrefix, bool enableHttpLogging)
+ public void Start(IEnumerable<string> urlPrefixes, bool enableHttpLogging)
{
- ReloadHttpServer(urlPrefix, enableHttpLogging);
+ ReloadHttpServer(urlPrefixes, enableHttpLogging);
}
public void StartWebSocketServer()
@@ -153,14 +153,8 @@ namespace MediaBrowser.Server.Implementations.ServerManager
/// <summary>
/// Restarts the Http Server, or starts it if not currently running
/// </summary>
- private void ReloadHttpServer(string urlPrefix, bool enableHttpLogging)
+ private void ReloadHttpServer(IEnumerable<string> urlPrefixes, bool enableHttpLogging)
{
- // Only reload if the port has changed, so that we don't disconnect any active users
- if (HttpServer != null && HttpServer.UrlPrefix.Equals(urlPrefix, StringComparison.OrdinalIgnoreCase))
- {
- return;
- }
-
DisposeHttpServer();
_logger.Info("Loading Http Server");
@@ -169,7 +163,7 @@ namespace MediaBrowser.Server.Implementations.ServerManager
{
HttpServer = _applicationHost.Resolve<IHttpServer>();
HttpServer.EnableHttpRequestLogging = enableHttpLogging;
- HttpServer.StartServer(urlPrefix);
+ HttpServer.StartServer(urlPrefixes);
}
catch (SocketException ex)
{
diff --git a/MediaBrowser.Server.Mono/Program.cs b/MediaBrowser.Server.Mono/Program.cs
index 59fc11c07..c65711704 100644
--- a/MediaBrowser.Server.Mono/Program.cs
+++ b/MediaBrowser.Server.Mono/Program.cs
@@ -33,6 +33,7 @@ namespace MediaBrowser.Server.Mono
var logManager = new NlogManager(appPaths.LogDirectoryPath, "server");
logManager.ReloadLogger(LogSeverity.Info);
+ logManager.AddConsoleOutput();
var logger = _logger = logManager.GetLogger("Main");
diff --git a/MediaBrowser.ServerApplication/ApplicationHost.cs b/MediaBrowser.ServerApplication/ApplicationHost.cs
index 13328d622..bf20c8fb8 100644
--- a/MediaBrowser.ServerApplication/ApplicationHost.cs
+++ b/MediaBrowser.ServerApplication/ApplicationHost.cs
@@ -94,11 +94,16 @@ namespace MediaBrowser.ServerApplication
/// Gets the HTTP server URL prefix.
/// </summary>
/// <value>The HTTP server URL prefix.</value>
- public string HttpServerUrlPrefix
+ private IEnumerable<string> HttpServerUrlPrefixes
{
get
{
- return "http://+:" + ServerConfigurationManager.Configuration.HttpServerPortNumber + "/" + WebApplicationName + "/";
+ var list = new List<string>
+ {
+ "http://+:" + ServerConfigurationManager.Configuration.HttpServerPortNumber + "/" + WebApplicationName + "/"
+ };
+
+ return list;
}
}
@@ -212,6 +217,8 @@ namespace MediaBrowser.ServerApplication
Logger.ErrorException("Error in {0}", ex, entryPoint.GetType().Name);
}
});
+
+ LogManager.RemoveConsoleOutput();
}
/// <summary>
@@ -462,7 +469,7 @@ namespace MediaBrowser.ServerApplication
{
try
{
- ServerManager.Start(HttpServerUrlPrefix, ServerConfigurationManager.Configuration.EnableHttpLevelLogging);
+ ServerManager.Start(HttpServerUrlPrefixes, ServerConfigurationManager.Configuration.EnableHttpLevelLogging);
}
catch (Exception ex)
{
@@ -494,7 +501,7 @@ namespace MediaBrowser.ServerApplication
HttpServer.EnableHttpRequestLogging = ServerConfigurationManager.Configuration.EnableHttpLevelLogging;
- if (!string.Equals(HttpServer.UrlPrefix, HttpServerUrlPrefix, StringComparison.OrdinalIgnoreCase))
+ if (!HttpServer.UrlPrefixes.SequenceEqual(HttpServerUrlPrefixes, StringComparer.OrdinalIgnoreCase))
{
NotifyPendingRestart();
}
@@ -695,8 +702,10 @@ namespace MediaBrowser.ServerApplication
try
{
- ServerAuthorization.AuthorizeServer(ServerConfigurationManager.Configuration.HttpServerPortNumber,
- HttpServerUrlPrefix, ServerConfigurationManager.Configuration.LegacyWebSocketPortNumber,
+ ServerAuthorization.AuthorizeServer(
+ ServerConfigurationManager.Configuration.HttpServerPortNumber,
+ HttpServerUrlPrefixes.First(),
+ ServerConfigurationManager.Configuration.LegacyWebSocketPortNumber,
UdpServerEntryPoint.PortNumber,
ConfigurationManager.CommonApplicationPaths.TempDirectory);
}
diff --git a/MediaBrowser.ServerApplication/MainStartup.cs b/MediaBrowser.ServerApplication/MainStartup.cs
index 7da17bc22..302136321 100644
--- a/MediaBrowser.ServerApplication/MainStartup.cs
+++ b/MediaBrowser.ServerApplication/MainStartup.cs
@@ -42,6 +42,7 @@ namespace MediaBrowser.ServerApplication
var logManager = new NlogManager(appPaths.LogDirectoryPath, "server");
logManager.ReloadLogger(LogSeverity.Debug);
+ logManager.AddConsoleOutput();
var logger = _logger = logManager.GetLogger("Main");