aboutsummaryrefslogtreecommitdiff
path: root/MediaBrowser.Common/Kernel/BaseKernel.cs
diff options
context:
space:
mode:
authorLukePulverenti Luke Pulverenti luke pulverenti <LukePulverenti Luke Pulverenti luke.pulverenti@gmail.com>2012-07-30 09:44:28 -0400
committerLukePulverenti Luke Pulverenti luke pulverenti <LukePulverenti Luke Pulverenti luke.pulverenti@gmail.com>2012-07-30 09:44:28 -0400
commit77669562743d725273ecd52677a6521aa0db7949 (patch)
tree573f7e5550098748ec1ed1d95968d3e4fb882db4 /MediaBrowser.Common/Kernel/BaseKernel.cs
parent882e20e9a5b05324ee75bb08ac09caec0034a9b4 (diff)
Extracted Logging into a separate, portable class library
Diffstat (limited to 'MediaBrowser.Common/Kernel/BaseKernel.cs')
-rw-r--r--MediaBrowser.Common/Kernel/BaseKernel.cs69
1 files changed, 56 insertions, 13 deletions
diff --git a/MediaBrowser.Common/Kernel/BaseKernel.cs b/MediaBrowser.Common/Kernel/BaseKernel.cs
index 09bb67218..f997aea5d 100644
--- a/MediaBrowser.Common/Kernel/BaseKernel.cs
+++ b/MediaBrowser.Common/Kernel/BaseKernel.cs
@@ -6,12 +6,12 @@ using System.Configuration;
using System.IO;
using System.Linq;
using System.Reflection;
-using MediaBrowser.Common.Configuration;
+using MediaBrowser.Model.Configuration;
using MediaBrowser.Common.Json;
-using MediaBrowser.Common.Logging;
using MediaBrowser.Common.Net;
using MediaBrowser.Common.Plugins;
-using MediaBrowser.Common.Progress;
+using MediaBrowser.Model.Progress;
+using MediaBrowser.Logging;
namespace MediaBrowser.Common.Kernel
{
@@ -49,6 +49,22 @@ namespace MediaBrowser.Common.Kernel
}
/// <summary>
+ /// Gets the path to the log directory
+ /// </summary>
+ private string LogDirectoryPath
+ {
+ get
+ {
+ return Path.Combine(ProgramDataPath, "logs");
+ }
+ }
+
+ /// <summary>
+ /// Gets or sets the path to the current log file
+ /// </summary>
+ private string LogFilePath { get; set; }
+
+ /// <summary>
/// Gets the current configuration
/// </summary>
public TConfigurationType Configuration { get; private set; }
@@ -73,12 +89,12 @@ namespace MediaBrowser.Common.Kernel
public BaseKernel()
{
ProgramDataPath = GetProgramDataPath();
-
- Logger.LoggerInstance = new FileLogger(Path.Combine(ProgramDataPath, "Logs"));
}
public virtual void Init(IProgress<TaskProgress> progress)
{
+ ReloadLogger();
+
ReloadConfiguration();
ReloadHttpServer();
@@ -86,6 +102,24 @@ namespace MediaBrowser.Common.Kernel
ReloadComposableParts();
}
+ private void ReloadLogger()
+ {
+ DisposeLogger();
+
+ if (!Directory.Exists(LogDirectoryPath))
+ {
+ Directory.CreateDirectory(LogDirectoryPath);
+ }
+
+ DateTime now = DateTime.Now;
+
+ LogFilePath = Path.Combine(LogDirectoryPath, now.ToString("dMyyyy") + "-" + now.Ticks + ".log");
+
+ FileStream fs = new FileStream(LogFilePath, FileMode.Append, FileAccess.Write, FileShare.Read);
+
+ Logger.LoggerInstance = new StreamLogger(fs);
+ }
+
/// <summary>
/// Uses MEF to locate plugins
/// Subclasses can use this to locate types within plugins
@@ -213,14 +247,6 @@ namespace MediaBrowser.Common.Kernel
HttpServer = new HttpServer("http://+:" + Configuration.HttpServerPortNumber + "/mediabrowser/");
}
- private void DisposeHttpServer()
- {
- if (HttpServer != null)
- {
- HttpServer.Dispose();
- }
- }
-
/// <summary>
/// This snippet will allow any plugin to reference another
/// </summary>
@@ -244,6 +270,23 @@ namespace MediaBrowser.Common.Kernel
public void Dispose()
{
DisposeHttpServer();
+ DisposeLogger();
+ }
+
+ private void DisposeHttpServer()
+ {
+ if (HttpServer != null)
+ {
+ HttpServer.Dispose();
+ }
+ }
+
+ private void DisposeLogger()
+ {
+ if (Logger.LoggerInstance != null)
+ {
+ Logger.LoggerInstance.Dispose();
+ }
}
}
}