Skip to content
Browse files

Merge remote-tracking branch 'remotes/origin/FEAT-3273-Switch_to_log4…

…net_Cleaner'

Conflicts:
	TvEngine3/TVLibrary/TvService/Service1.cs
  • Loading branch information...
2 parents 62dda43 + f9351d9 commit 03e4d9c61810539e866f7ce36322db8d23b621cb @Sebastiii Sebastiii committed Apr 1, 2013
View
8 Common-MP-TVE3/Common.Utils/Common.Utils.csproj
@@ -71,6 +71,9 @@
<CodeAnalysisRuleSet>AllRules.ruleset</CodeAnalysisRuleSet>
</PropertyGroup>
<ItemGroup>
+ <Reference Include="log4net">
+ <HintPath>..\..\mediaportal\MediaPortal.Base\log4net.dll</HintPath>
+ </Reference>
<Reference Include="System" />
<Reference Include="System.Core">
<RequiredTargetFramework>3.5</RequiredTargetFramework>
@@ -87,6 +90,11 @@
<Compile Include="Compatibility\CompatibleVersionAttribute.cs" />
<Compile Include="Compatibility\SubsystemVersionAttribute.cs" />
<Compile Include="Compatibility\UsesSubsystemAttribute.cs" />
+ <Compile Include="Logger\CommonLog4NetLogger.cs" />
+ <Compile Include="Logger\CommonLogger.cs" />
+ <Compile Include="Logger\CommonLogLevel.cs" />
+ <Compile Include="Logger\CommonLogType.cs" />
+ <Compile Include="Logger\ICommonLogger.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
View
322 Common-MP-TVE3/Common.Utils/Logger/CommonLog4NetLogger.cs
@@ -0,0 +1,322 @@
+using System;
+using System.Collections.Generic;
+using System.IO;
+using System.Linq;
+using System.Text;
+using System.Text.RegularExpressions;
+using System.Xml;
+using log4net;
+
+namespace MediaPortal.Common.Utils.Logger
+{
+ public class CommonLog4NetLogger: ICommonLogger
+ {
+
+ #region variables
+ protected CommonLogLevel MinLevel = CommonLogLevel.All;
+ protected Dictionary<CommonLogType, ILog> _loggers;
+ #endregion
+
+ #region Constructors/Destructors
+ public CommonLog4NetLogger(string loggerName, string dataPath, string logPath)
+ {
+ var logFile = Path.Combine(dataPath, "Log4Net.config");
+ if (!File.Exists(logFile))
+ WriteDefaultConfig(logFile);
+
+ var xmlDoc = new XmlDocument();
+ var fs = new FileStream(Path.Combine(dataPath, "Log4Net.config"), FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
+ xmlDoc.Load(fs);
+ fs.Close();
+
+ var nodeList = xmlDoc.SelectNodes("configuration/log4net/appender/file");
+ if (nodeList != null)
+ foreach (var node in nodeList.Cast<XmlNode>().Where(node => node.Attributes != null)) {
+ if (node != null)
+ if (node.Attributes != null)
+ foreach (var attribute in node.Attributes.Cast<XmlAttribute>().Where(attribute => attribute.Name.Equals("value")))
+ {
+ if (attribute.Value != null)
+ attribute.Value = Path.Combine(logPath, Path.GetFileName(attribute.Value)).Replace("[Name]", loggerName);
+ break;
+ }
+ }
+ var mStream = new MemoryStream();
+ xmlDoc.Save(mStream);
+ mStream.Seek(0, SeekOrigin.Begin);
+ log4net.Config.XmlConfigurator.Configure(mStream);
+
+ _loggers = new Dictionary<CommonLogType, ILog>();
+ foreach (CommonLogType logType in Enum.GetValues(typeof(CommonLogType)))
+ {
+ _loggers.Add(logType, LogManager.GetLogger(logType.ToString()));
+ }
+ }
+
+ #endregion
+
+ #region WriteDefaultConfig
+ private void WriteDefaultConfig(string logFile)
+ {
+ TextWriter tw = new StreamWriter(logFile);
+ tw.WriteLine("<?xml version=\"1.0\" encoding=\"utf-8\" ?>");
+ tw.WriteLine("<configuration>)");
+ tw.WriteLine(" <configSections>");
+ tw.WriteLine(" <section name=\"log4net\" type=\"log4net.Config.Log4NetConfigurationSectionHandler, log4net\"/>");
+ tw.WriteLine(" </configSections>");
+ tw.WriteLine(" ");
+ tw.WriteLine(" <log4net>");
+ tw.WriteLine(" <appender name=\"DefaultLogAppender\" type=\"log4net.Appender.RollingFileAppender\">");
+ tw.WriteLine(" <file value=\"[Name].log\" />");
+ tw.WriteLine(" <appendToFile value=\"true\" />");
+ tw.WriteLine(" <rollingStyle value=\"Once\" />");
+ tw.WriteLine(" <maxSizeRollBackups value=\"4\" />");
+ tw.WriteLine(" <maximumFileSize value=\"1MB\" />");
+ tw.WriteLine(" <staticLogFileName value=\"true\" />");
+ tw.WriteLine(" <layout type=\"log4net.Layout.PatternLayout\">");
+ tw.WriteLine(" <conversionPattern value=\"[%date] [%-7logger] [%-9thread] [%-5level] - %message%newline\" />");
+ tw.WriteLine(" </layout>");
+ tw.WriteLine(" </appender>");
+ tw.WriteLine(" ");
+ tw.WriteLine(" <appender name=\"ErrorLogAppender\" type=\"log4net.Appender.RollingFileAppender\">");
+ tw.WriteLine(" <file value=\"[Name]-Error.log\" />");
+ tw.WriteLine(" <appendToFile value=\"true\" />");
+ tw.WriteLine(" <rollingStyle value=\"Once\" />");
+ tw.WriteLine(" <maxSizeRollBackups value=\"4\" />");
+ tw.WriteLine(" <maximumFileSize value=\"1MB\" />");
+ tw.WriteLine(" <staticLogFileName value=\"true\" />");
+ tw.WriteLine(" <layout type=\"log4net.Layout.PatternLayout\">");
+ tw.WriteLine(" <conversionPattern value=\"[%date] [%-7logger] [%-9thread] [%-5level] - %message%newline\" />");
+ tw.WriteLine(" </layout>");
+ tw.WriteLine(" </appender>");
+ tw.WriteLine(" ");
+ tw.WriteLine(" <appender name=\"ErrorLossyFileAppender\" type=\"log4net.Appender.BufferingForwardingAppender\">");
+ tw.WriteLine(" <bufferSize value=\"1\" />");
+ tw.WriteLine(" <lossy value=\"true\"/>");
+ tw.WriteLine(" <evaluator type=\"log4net.Core.LevelEvaluator\">");
+ tw.WriteLine(" <threshold value=\"ERROR\" />");
+ tw.WriteLine(" </evaluator>");
+ tw.WriteLine(" <appender-ref ref=\"ErrorLogAppender\" />");
+ tw.WriteLine(" </appender>");
+ tw.WriteLine(" ");
+ tw.WriteLine(" <appender name=\"ConsoleAppender\" type=\"log4net.Appender.ConsoleAppender\">");
+ tw.WriteLine(" <layout type=\"log4net.Layout.PatternLayout\">");
+ tw.WriteLine(" <conversionPattern value=\"[%date] [%-7logger] [%-9thread] [%-5level] - %message%newline\" />");
+ tw.WriteLine(" </layout>");
+ tw.WriteLine(" </appender>");
+ tw.WriteLine(" ");
+ tw.WriteLine(" <root>");
+ tw.WriteLine(" <level value=\"ALL\" />");
+ tw.WriteLine(" <appender-ref ref=\"ConsoleAppender\" />");
+ tw.WriteLine(" <appender-ref ref=\"ErrorLossyFileAppender\" />");
+ tw.WriteLine(" <appender-ref ref=\"DefaultLogAppender\" />");
+ tw.WriteLine(" </root>");
+ tw.WriteLine(" </log4net>");
+ tw.WriteLine(" ");
+ tw.WriteLine("</configuration>");
+ tw.Flush();
+ tw.Close();
+ }
+
+ #endregion
+
+ #region Implementation of ICommonLogger
+
+ /// <summary>
+ /// Gets or sets the log level.
+ /// </summary>
+ /// <value>A <see cref="CommonLogLevel"/> value that indicates the minimum level messages must have to be
+ /// written to the logger.</value>
+ public CommonLogLevel LogLevel
+ {
+ get { return MinLevel; }
+ set { MinLevel = value; }
+ }
+
+
+ /// <summary>
+ /// Writes a debug message to the Log
+ /// </summary>
+ /// <param name="logType">Defines log4net logger</param>
+ /// <param name="format">A composite format string.</param>
+ /// <param name="args">An array of objects to write using format.</param>
+ public void Debug(CommonLogType logType, string format, params object[] args)
+ {
+ if (MinLevel >= CommonLogLevel.Debug)
+ {
+ _loggers[logType].Debug(FormatString(format, args));
+ }
+ }
+
+ /// <summary>
+ /// Writes an informational message to the Log
+ /// </summary>
+ /// <param name="logType">Defines log4net logger</param>
+ /// <param name="format">A composite format string.</param>
+ /// <param name="args">An array of objects to write using format.</param>
+ public void Info(CommonLogType logType, string format, params object[] args)
+ {
+ if (MinLevel >= CommonLogLevel.Information)
+ {
+ _loggers[logType].Info(FormatString(format, args));
+ }
+ }
+
+ /// <summary>
+ /// Writes a warning message to the Log
+ /// </summary>
+ /// <param name="logType">Defines log4net logger</param>
+ /// <param name="format">A composite format string.</param>
+ /// <param name="args">An array of objects to write using format.</param>
+ public void Warn(CommonLogType logType, string format, params object[] args)
+ {
+ if (MinLevel >= CommonLogLevel.Warning)
+ {
+ _loggers[logType].Warn(FormatString(format, args));
+ }
+ }
+
+ /// <summary>
+ /// Writes an error message to the Log
+ /// </summary>
+ /// <param name="logType">Defines log4net logger</param>
+ /// <param name="format">A composite format string.</param>
+ /// <param name="args">An array of objects to write using format.</param>
+ public void Error(CommonLogType logType, string format, params object[] args)
+ {
+ _loggers[logType].Error(FormatString(format, args));
+ }
+
+ /// <summary>
+ /// Writes an Error <see cref="Exception"/> to the Log
+ /// </summary>
+ /// <param name="logType">Defines log4net logger</param>
+ /// <param name="ex">The <see cref="Exception"/> to write.</param>
+ public void Error(CommonLogType logType, Exception ex)
+ {
+ _loggers[logType].Error(FormatException(ex));
+ }
+
+ /// <summary>
+ /// Writes an error <see cref="Exception"/> to the Log
+ /// </summary>
+ /// <param name="logType">Defines log4net logger</param>
+ /// <param name="message">A message string.</param>
+ /// <param name="ex">The <see cref="Exception"/> to write.</param>
+ public void Error(CommonLogType logType, string message, Exception ex)
+ {
+ Error(logType, message);
+ Error(logType, ex);
+ }
+
+ /// <summary>
+ /// Writes a critical error system message to the Log
+ /// </summary>
+ /// <param name="logType">Defines log4net logger</param>
+ /// <param name="format">A composite format string.</param>
+ /// <param name="args">An array of objects to write using format.</param>
+ public void Critical(CommonLogType logType, string format, params object[] args)
+ {
+ if (MinLevel >= CommonLogLevel.Critical)
+ {
+ _loggers[logType].Fatal(FormatString(format, args));
+ }
+ }
+
+
+ /// <summary>
+ /// Writes an Critical error <see cref="Exception"/> to the Log
+ /// </summary>
+ /// <param name="logType">Defines log4net logger</param>
+ /// <param name="ex">The <see cref="Exception"/> to write.</param>
+ public void Critical(CommonLogType logType, Exception ex)
+ {
+ if (MinLevel >= CommonLogLevel.Critical)
+ {
+ _loggers[logType].Fatal(FormatException(ex));
+ }
+ }
+
+ /// <summary>
+ /// Writes an critical <see cref="Exception"/> to the Log
+ /// </summary>
+ /// <param name="logType">Defines log4net logger</param>
+ /// <param name="message">A message string.</param>
+ /// <param name="ex">The <see cref="Exception"/> to write.</param>
+ public void Critical(CommonLogType logType, string message, Exception ex)
+ {
+ Critical(logType, message);
+ Critical(logType, ex);
+ }
+
+ #endregion
+
+ #region protected routines
+
+ /// <summary>
+ /// Writes an <see cref="Exception"/> instance.
+ /// </summary>
+ /// <param name="ex">The <see cref="Exception"/> to write.</param>
+ protected string FormatException(Exception ex)
+ {
+ var sb = new StringBuilder();
+ sb.AppendFormat("Exception: " + SafeString(ex.ToString()));
+ sb.AppendFormat(" Message: " + SafeString(ex.Message));
+ sb.AppendFormat(" Site : " + ex.TargetSite);
+ sb.AppendFormat(" Source : " + ex.Source);
+ if (ex.InnerException != null)
+ {
+ sb.AppendFormat(" Inner Exception(s):");
+ {
+ var stack = new Stack<Exception>();
+ stack.Push(ex);
+ while (stack.Count > 0)
+ {
+ var except = stack.Pop();
+ sb.AppendFormat(" -> " + except.Message);
+ if (except.InnerException != null)
+ {
+ stack.Push(except.InnerException);
+ }
+ }
+ }
+ }
+ sb.AppendFormat(" Stack Trace:");
+ sb.AppendFormat(" " + ex.StackTrace);
+ return sb.ToString();
+ }
+
+ /// <summary>
+ /// Replaces a password inside the string by stars
+ /// </summary>
+ /// <param name="logtext">String to replace</param>
+ /// <returns>String without password</returns>
+ protected string SafeString(String logtext)
+ {
+ return new Regex(@"Password=[^;]*;", RegexOptions.IgnoreCase).Replace(logtext, "Password=***;");
+ }
+
+ /// <summary>
+ /// Check for valid args and return formated string
+ /// </summary>
+ /// <param name="format">A composite format string.</param>
+ /// <param name="args">An array of objects to write using format.</param>
+ /// <returns>formated string</returns>
+ protected string FormatString(string format, params object[] args)
+ {
+ var result = format;
+ if (args != null && args.Length > 0)
+ {
+ try
+ {
+ result = string.Format(format, args);
+ }
+ catch {}
+ }
+ return result;
+ }
+
+ #endregion
+
+ }
+}
View
17 Common-MP-TVE3/Common.Utils/Logger/CommonLogLevel.cs
@@ -0,0 +1,17 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+
+namespace MediaPortal.Common.Utils.Logger
+{
+ public enum CommonLogLevel
+ {
+ Critical,
+ Error,
+ Warning,
+ Information,
+ Debug,
+ All
+ }
+}
View
22 Common-MP-TVE3/Common.Utils/Logger/CommonLogType.cs
@@ -0,0 +1,22 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+
+namespace MediaPortal.Common.Utils.Logger
+{
+ public enum CommonLogType
+ {
+ Log =1,
+ Error = 2,
+ Config = 3 ,
+ Recorder = 100,
+ EPG =101,
+ VMR9 = 102,
+ MusicShareWatcher =103,
+ WebEPG = 104,
+ Tv =200,
+ TvConfig = 201,
+ TvPlugIn = 202,
+ }
+}
View
7 Common-MP-TVE3/Common.Utils/Logger/CommonLogger.cs
@@ -0,0 +1,7 @@
+namespace MediaPortal.Common.Utils.Logger
+{
+ public static class CommonLogger
+ {
+ public static ICommonLogger Instance { get; set; }
+ }
+}
View
87 Common-MP-TVE3/Common.Utils/Logger/ICommonLogger.cs
@@ -0,0 +1,87 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+
+namespace MediaPortal.Common.Utils.Logger
+{
+ public interface ICommonLogger
+ {
+ /// <summary>
+ /// Gets or sets the log level.
+ /// </summary>
+ /// <value>A <see cref="CommonLogLevel"/> value that indicates the minimum level messages must have to be
+ /// written to the logger.</value>
+ CommonLogLevel LogLevel { get; set; }
+
+ /// <summary>
+ /// Writes a debug message to the Log
+ /// </summary>
+ /// <param name="logType">Defines log4net logger</param>
+ /// <param name="format">A composite format string.</param>
+ /// <param name="args">An array of objects to write using format.</param>
+ void Debug(CommonLogType logType, string format, params object[] args);
+
+ /// <summary>
+ /// Writes an informational message to the Log
+ /// </summary>
+ /// <param name="logType">Defines log4net logger</param>
+ /// <param name="format">A composite format string.</param>
+ /// <param name="args">An array of objects to write using format.</param>
+ void Info(CommonLogType logType, string format, params object[] args);
+
+ /// <summary>
+ /// Writes a warning message to the Log
+ /// </summary>
+ /// <param name="logType">Defines log4net logger</param>
+ /// <param name="format">A composite format string.</param>
+ /// <param name="args">An array of objects to write using format.</param>
+ void Warn(CommonLogType logType, string format, params object[] args);
+
+ /// <summary>
+ /// Writes an error message to the Log
+ /// </summary>
+ /// <param name="logType">Defines log4net logger</param>
+ /// <param name="format">A composite format string.</param>
+ /// <param name="args">An array of objects to write using format.</param>
+ void Error(CommonLogType logType, string format, params object[] args);
+
+ /// <summary>
+ /// Writes an Error <see cref="Exception"/> to the Log
+ /// </summary>
+ /// <param name="logType">Defines log4net logger</param>
+ /// <param name="ex">The <see cref="Exception"/> to write.</param>
+ void Error(CommonLogType logType, Exception ex);
+
+ /// <summary>
+ /// Writes an error <see cref="Exception"/> to the Log
+ /// </summary>
+ /// <param name="logType">Defines log4net logger</param>
+ /// <param name="message">A message string.</param>
+ /// <param name="ex">The <see cref="Exception"/> to write.</param>
+ void Error(CommonLogType logType, string message, Exception ex);
+
+ /// <summary>
+ /// Writes a critical error system message to the Log
+ /// </summary>
+ /// <param name="logType">Defines log4net logger</param>
+ /// <param name="format">A composite format string.</param>
+ /// <param name="args">An array of objects to write using format.</param>
+ void Critical(CommonLogType logType, string format, params object[] args);
+
+ /// <summary>
+ /// Writes an Critical error <see cref="Exception"/> to the Log
+ /// </summary>
+ /// <param name="logType">Defines log4net logger</param>
+ /// <param name="ex">The <see cref="Exception"/> to write.</param>
+ void Critical(CommonLogType logType, Exception ex);
+
+ /// <summary>
+ /// Writes an critical <see cref="Exception"/> to the Log
+ /// </summary>
+ /// <param name="logType">Defines log4net logger</param>
+ /// <param name="message">A message string.</param>
+ /// <param name="ex">The <see cref="Exception"/> to write.</param>
+ void Critical(CommonLogType logType, string message, Exception ex);
+ }
+}
View
11 TvEngine3/TVLibrary/SetupTv/Startup.cs
@@ -28,6 +28,7 @@
using System.Reflection;
using System.Threading;
using System.Diagnostics;
+using MediaPortal.Common.Utils.Logger;
using TvControl;
using TvDatabase;
using TvLibrary.Log;
@@ -100,6 +101,16 @@ public static void Application_ThreadException(object sender, ThreadExceptionEve
[STAThread]
public static void Main(string[] arguments)
{
+ // Init Common logger -> this will enable TVPlugin to write in the Mediaportal.log file
+ var loggerName = Path.GetFileNameWithoutExtension(Environment.GetCommandLineArgs()[0]);
+ var dataPath = Log.GetPathName();
+ var loggerPath = Path.Combine(dataPath, "log");
+#if DEBUG
+ if (loggerName != null) loggerName = loggerName.Replace(".vshost", "");
+#endif
+ CommonLogger.Instance = new CommonLog4NetLogger(loggerName, dataPath, loggerPath);
+
+
Thread.CurrentThread.Name = "SetupTv";
Process[] p = Process.GetProcessesByName(Process.GetCurrentProcess().ProcessName);
View
16 TvEngine3/TVLibrary/TVServer.Base/log4net.config
@@ -6,31 +6,31 @@
<log4net>
<appender name="DefaultLogAppender" type="log4net.Appender.RollingFileAppender">
- <file value="tv.log" />
+ <file value="[Name].log" />
<appendToFile value="true" />
<rollingStyle value="Once" />
- <maxSizeRollBackups value="4" />
+ <maxSizeRollBackups value="5" />
<maximumFileSize value="1MB" />
<staticLogFileName value="true" />
<layout type="log4net.Layout.PatternLayout">
- <conversionPattern value="[%date] [%-7timestamp] [%-9thread] [%-5level] - %message%newline" />
+ <conversionPattern value="[%date] [%-7logger] [%-9thread] [%-5level] - %message%newline" />
</layout>
</appender>
<appender name="ErrorLogAppender" type="log4net.Appender.RollingFileAppender">
- <file value="Error.log" />
+ <file value="[Name]-Error.log" />
<appendToFile value="true" />
<rollingStyle value="Once" />
- <maxSizeRollBackups value="4" />
+ <maxSizeRollBackups value="5" />
<maximumFileSize value="1MB" />
<staticLogFileName value="true" />
<layout type="log4net.Layout.PatternLayout">
- <conversionPattern value="[%date] [%-7timestamp] [%-9thread] [%-5level] - %message%newline" />
+ <conversionPattern value="[%date] [%-7logger] [%-9thread] [%-5level] - %message%newline" />
</layout>
</appender>
<appender name="ErrorLossyFileAppender" type="log4net.Appender.BufferingForwardingAppender">
- <bufferSize value="25" />
+ <bufferSize value="1" />
<lossy value="true"/>
<evaluator type="log4net.Core.LevelEvaluator">
<threshold value="ERROR" />
@@ -40,7 +40,7 @@
<appender name="ConsoleAppender" type="log4net.Appender.ConsoleAppender">
<layout type="log4net.Layout.PatternLayout">
- <conversionPattern value="[%-7timestamp] [%-9thread] [%-5level] - %message%newline" />
+ <conversionPattern value="[%date] [%-9thread] [%-5level] - %message%newline" />
</layout>
</appender>
View
15 TvEngine3/TVLibrary/TvLibrary.Interfaces/Logging/Log.cs
@@ -24,6 +24,7 @@
using System.Text;
using System.Text.RegularExpressions;
using System.Threading;
+using MediaPortal.Common.Utils.Logger;
namespace TvLibrary.Log
{
@@ -406,7 +407,6 @@ private static void WriteToFile(LogType logType, string format, params object[]
{
try
{
- string logFileName = GetFileName(logType);
string logLine = string.Format(format, arg);
if (IsRepetition(logLine))
@@ -415,6 +415,18 @@ private static void WriteToFile(LogType logType, string format, params object[]
}
CacheLogLine(logLine);
+ // implementation
+ switch (logType)
+ {
+ case LogType.Debug: CommonLogger.Instance.Debug(CommonLogType.Log, format, arg); break;
+ case LogType.Info: CommonLogger.Instance.Info(CommonLogType.Log, format, arg); break;
+ case LogType.Error:CommonLogger.Instance.Error(CommonLogType.Log, format, arg); break;
+ case LogType.Epg: CommonLogger.Instance.Info(CommonLogType.EPG, format, arg); break;
+ }
+
+
+ /*
+ string logFileName = GetFileName(logType);
if (CheckLogPrepared(logFileName))
{
using (StreamWriter writer = new StreamWriter(logFileName, true, Encoding.UTF8))
@@ -428,6 +440,7 @@ private static void WriteToFile(LogType logType, string format, params object[]
writer.Close();
}
}
+ */
}
catch (Exception) {}
}
View
4 TvEngine3/TVLibrary/TvLibrary.Interfaces/TvLibrary.Interfaces.csproj
@@ -137,6 +137,10 @@
<Compile Include="TvException.cs" />
</ItemGroup>
<ItemGroup>
+ <ProjectReference Include="..\..\..\Common-MP-TVE3\Common.Utils\Common.Utils.csproj">
+ <Project>{F6EDA1F3-3DCD-43F4-8A90-E32DA70C8227}</Project>
+ <Name>Common.Utils</Name>
+ </ProjectReference>
<ProjectReference Include="..\..\..\Common-MP-TVE3\DirectShowLib\DirectShowLib.csproj">
<Project>{CE009BFA-5EF6-4153-B2A1-2FA79698A9AE}</Project>
<Name>DirectShowLib</Name>
View
12 TvEngine3/TVLibrary/TvService/Service1.cs
@@ -26,13 +26,15 @@
using System.Configuration.Install;
using System.Diagnostics;
using System.Reflection;
+using System.IO;
using System.Security.Principal;
using System.ServiceProcess;
using System.Threading;
using System.Windows.Forms;
using System.Runtime.CompilerServices;
using System.Runtime.Remoting;
using System.Xml;
+using MediaPortal.Common.Utils.Logger;
using TvDatabase;
using TvLibrary.Log;
using TvControl;
@@ -106,6 +108,16 @@ private void CurrentDomain_UnhandledException(object sender, UnhandledExceptionE
/// </summary>
private static void Main(string[] args)
{
+ // Init Common logger -> this will enable TVPlugin to write in the Mediaportal.log file
+ var loggerName = Path.GetFileNameWithoutExtension(Environment.GetCommandLineArgs()[0]);
+ var dataPath = Log.GetPathName();
+ var loggerPath = Path.Combine(dataPath, "log");
+#if DEBUG
+ if (loggerName != null) loggerName = loggerName.Replace(".vshost", "");
+#endif
+ CommonLogger.Instance = new CommonLog4NetLogger(loggerName, dataPath, loggerPath);
+
+
NameValueCollection appSettings = ConfigurationManager.AppSettings;
appSettings.Set("GentleConfigFile", String.Format(@"{0}\gentle.config", PathManager.GetDataPath));
View
16 mediaportal/MediaPortal.Base/log4net.config
@@ -6,31 +6,31 @@
<log4net>
<appender name="DefaultLogAppender" type="log4net.Appender.RollingFileAppender">
- <file value="MediaPortal.log" />
+ <file value="[Name].log" />
<appendToFile value="true" />
<rollingStyle value="Once" />
- <maxSizeRollBackups value="4" />
+ <maxSizeRollBackups value="5" />
<maximumFileSize value="1MB" />
<staticLogFileName value="true" />
<layout type="log4net.Layout.PatternLayout">
- <conversionPattern value="[%date] [%-7timestamp] [%-9thread] [%-5level] - %message%newline" />
+ <conversionPattern value="[%date] [%-7logger] [%-9thread] [%-5level] - %message%newline" />
</layout>
</appender>
<appender name="ErrorLogAppender" type="log4net.Appender.RollingFileAppender">
- <file value="Error.log" />
+ <file value="[Name]-Error.log" />
<appendToFile value="true" />
<rollingStyle value="Once" />
- <maxSizeRollBackups value="4" />
+ <maxSizeRollBackups value="5" />
<maximumFileSize value="1MB" />
<staticLogFileName value="true" />
<layout type="log4net.Layout.PatternLayout">
- <conversionPattern value="[%date] [%-7timestamp] [%-9thread] [%-5level] - %message%newline" />
+ <conversionPattern value="[%date] [%-7logger] [%-9thread] [%-5level] - %message%newline" />
</layout>
</appender>
<appender name="ErrorLossyFileAppender" type="log4net.Appender.BufferingForwardingAppender">
- <bufferSize value="25" />
+ <bufferSize value="1" />
<lossy value="true"/>
<evaluator type="log4net.Core.LevelEvaluator">
<threshold value="ERROR" />
@@ -40,7 +40,7 @@
<appender name="ConsoleAppender" type="log4net.Appender.ConsoleAppender">
<layout type="log4net.Layout.PatternLayout">
- <conversionPattern value="[%-7timestamp] [%-9thread] [%-5level] - %message%newline" />
+ <conversionPattern value="[%date] [%-9thread] [%-5level] - %message%newline" />
</layout>
</appender>
View
112 mediaportal/Utils/ServiceImplementations/Log4NetWrapper.cs
@@ -0,0 +1,112 @@
+using System;
+using MediaPortal.Services;
+using MediaPortal.Common.Utils.Logger;
+
+namespace MediaPortal.ServiceImplementations
+{
+ public class Log4NetWrapper : MediaPortal.Services.ILog
+ {
+ #region Variables
+ private bool _configuration;
+ #endregion
+
+ #region Constructors/Destructors
+ public Log4NetWrapper()
+ {
+ }
+ #endregion
+
+ #region Implementation of ILog
+ public void BackupLogFiles() {}
+ public void BackupLogFile(LogType logType) {}
+
+
+ public void Info(string format, params object[] args)
+ {
+ Info(LogType.Log, format, args);
+ }
+
+ public void Info(LogType type, string format, params object[] args)
+ {
+ CommonLogger.Instance.Info(ConvertToCommonLogType(type), format, args);
+ }
+
+ public void Warn(string format, params object[] args)
+ {
+ Warn(LogType.Log, format, args);
+ }
+
+ public void Warn(LogType type, string format, params object[] args)
+ {
+ CommonLogger.Instance.Warn(ConvertToCommonLogType(type), format, args);
+ }
+
+ public void Debug(string format, params object[] args)
+ {
+ Debug(LogType.Log, format, args);
+ }
+
+ public void Debug(LogType type, string format, params object[] args)
+ {
+ CommonLogger.Instance.Debug(ConvertToCommonLogType(type), format, args);
+ }
+
+ public void Error(string format, params object[] args)
+ {
+ Error(LogType.Error, format, args);
+ }
+
+ public void Error(LogType type, string format, params object[] args)
+ {
+ CommonLogger.Instance.Error(ConvertToCommonLogType(type), format, args);
+ }
+
+ public void Error(Exception ex)
+ {
+ CommonLogger.Instance.Error(ConvertToCommonLogType(LogType.Log), ex);
+ }
+
+ public void SetConfigurationMode()
+ {
+ _configuration = true;
+ }
+
+ public void SetLogLevel(Level logLevel)
+ {
+ CommonLogger.Instance.LogLevel = ConvertToCommonLogLevel(logLevel);
+ }
+
+ #endregion
+
+ #region private methods
+ private CommonLogType ConvertToCommonLogType(LogType type)
+ {
+ if (_configuration) return CommonLogType.Config;
+ switch (type)
+ {
+ case LogType.Recorder: return CommonLogType.Recorder;
+ case LogType.Error: return CommonLogType.Error;
+ case LogType.EPG: return CommonLogType.EPG;
+ case LogType.VMR9: return CommonLogType.VMR9;
+ case LogType.MusicShareWatcher: return CommonLogType.MusicShareWatcher;
+ case LogType.WebEPG: return CommonLogType.WebEPG;
+ default: return CommonLogType.Log;
+ }
+ }
+
+ private CommonLogLevel ConvertToCommonLogLevel(Level logLevel)
+ {
+ switch (logLevel)
+ {
+ case Level.Debug: return CommonLogLevel.Debug;
+ case Level.Error: return CommonLogLevel.Error;
+ case Level.Information: return CommonLogLevel.Information;
+ case Level.Warning: return CommonLogLevel.Warning;
+ default: return CommonLogLevel.All;
+ }
+ }
+
+ #endregion
+
+ }
+}
View
172 mediaportal/Utils/ServiceImplementations/log4netLogger.cs
@@ -1,172 +0,0 @@
-using System;
-using System.IO;
-using System.Windows.Forms;
-using System.Xml;
-using log4net;
-using MediaPortal.Configuration;
-using MediaPortal.Profile;
-using MediaPortal.Services;
-
-namespace MediaPortal.ServiceImplementations
-{
- public class Log4netLogger : MediaPortal.Services.ILog
- {
- #region Variables
- private Level _minLevel;
- private bool _configuration;
- #endregion
-
- #region Constructors/Destructors
- public Log4netLogger()
- {
- string logPath = Config.GetFolder(Config.Dir.Log);
- using (Settings xmlreader = new MPSettings())
- {
- _minLevel = (Level)Enum.Parse(typeof(Level), xmlreader.GetValueAsString("general", "loglevel", "2"));
- }
- _configuration = false;
- string appPath = Path.GetDirectoryName(Application.ExecutablePath);
-
- XmlDocument xmlDoc = new XmlDocument();
- FileStream fs = new FileStream(Path.Combine(appPath, "log4net.config"), FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
- xmlDoc.Load(fs);
- fs.Close();
-
- XmlNodeList nodeList = xmlDoc.SelectNodes("configuration/log4net/appender/file");
- foreach (XmlNode node in nodeList)
- {
- if (node.Attributes != null)
- {
- foreach (XmlAttribute attribute in node.Attributes)
- {
- if (attribute.Name.Equals("value"))
- {
- attribute.Value = Path.Combine(logPath, Path.GetFileName(attribute.Value));
- break;
- }
- }
- }
- }
- MemoryStream mStream = new MemoryStream();
- xmlDoc.Save(mStream);
- mStream.Seek(0, SeekOrigin.Begin);
- log4net.Config.XmlConfigurator.Configure(mStream);
- }
- #endregion
-
- private string GetLogTypeName(LogType type)
- {
- if (_configuration) return "Config";
- switch (type)
- {
- case LogType.Recorder: return ("Rec");
- case LogType.Error: return ("Error");
- case LogType.EPG: return ("EPG");
- case LogType.VMR9:return ("VMR9");
- case LogType.MusicShareWatcher:return ("MusicSh");
- case LogType.WebEPG:return ("WebEPG");
- default: return ("Log");
- }
- }
-
-
- #region Implementation of ILog
- public void BackupLogFiles() {}
- public void BackupLogFile(LogType logType) {}
-
-
- public void Info(string format, params object[] args)
- {
- Info(LogType.Log, format, args);
- }
-
- public void Info(LogType type, string format, params object[] args)
- {
- if (Level.Information <= _minLevel)
- {
- if (args.Length > 0)
- {
- LogManager.GetLogger(GetLogTypeName(type)).InfoFormat(format, args);
- }
- else
- {
- LogManager.GetLogger(GetLogTypeName(type)).Info(format);
- }
- }
- }
-
- public void Warn(string format, params object[] args)
- {
- Warn(LogType.Log, format, args);
- }
-
- public void Warn(LogType type, string format, params object[] args)
- {
- if (Level.Warning <= _minLevel)
- {
- if (args.Length > 0)
- {
- LogManager.GetLogger(GetLogTypeName(type)).WarnFormat(format, args);
- }
- else
- {
- LogManager.GetLogger(GetLogTypeName(type)).Warn(format);
- }
- }
- }
-
- public void Debug(string format, params object[] args)
- {
- Debug(LogType.Log, format, args);
- }
-
- public void Debug(LogType type, string format, params object[] args)
- {
- if (Level.Debug <= _minLevel)
- {
- if (args.Length > 0)
- {
- LogManager.GetLogger(GetLogTypeName(type)).DebugFormat(format, args);
- }
- else
- {
- LogManager.GetLogger(GetLogTypeName(type)).Debug(format);
- }
- }
- }
-
- public void Error(string format, params object[] args)
- {
- Error(LogType.Error, format, args);
- }
-
- public void Error(LogType type, string format, params object[] args)
- {
- if (args.Length > 0)
- {
- LogManager.GetLogger(GetLogTypeName(type)).ErrorFormat(format, args);
- }
- else
- {
- LogManager.GetLogger(GetLogTypeName(type)).Error(format);
- }
- }
-
- public void Error(Exception ex)
- {
- LogManager.GetLogger(LogType.Log.GetType()).Error("", ex);
- }
-
- public void SetConfigurationMode()
- {
- _configuration = true;
- }
-
- public void SetLogLevel(Level logLevel)
- {
- _minLevel = logLevel;
- }
-
- #endregion
- }
-}
View
15 mediaportal/Utils/Services/GlobalServiceProvider.cs
@@ -18,10 +18,12 @@
#endregion
+using System;
using System.IO;
using System.Windows.Forms;
using MediaPortal.ServiceImplementations;
using MediaPortal.Threading;
+using MediaPortal.Common.Utils.Logger;
namespace MediaPortal.Services
{
@@ -112,7 +114,18 @@ public static bool IsRegistered<T>()
private static ILog LogServiceRequested(ServiceProvider services)
{
- ILog log = new LogImpl();
+ // Init Common logger -> this will enable TVPlugin to write in the Mediaportal.log file
+ var loggerName = Path.GetFileNameWithoutExtension(Environment.GetCommandLineArgs()[0]);
+ var dataPath = Configuration.Config.GetFolder(Configuration.Config.Dir.Config);
+ var loggerPath = Configuration.Config.GetFolder(Configuration.Config.Dir.Log);
+#if DEBUG
+ if (loggerName != null) loggerName = loggerName.Replace(".vshost", "");
+#endif
+ CommonLogger.Instance = new CommonLog4NetLogger(loggerName, dataPath, loggerPath);
+
+ // Init wrapper from CommonLogger to the current ILog interface
+ // -> this will ensure that all external plugins will work without recompile
+ ILog log = new Log4NetWrapper(); //LogImpl();
services.Add<ILog>(log);
return log;
View
8 mediaportal/Utils/Utils.csproj
@@ -148,7 +148,7 @@
<Compile Include="Localisation\StringsFile\StringSection.cs" />
<Compile Include="Localisation\StringsFile\StringFile.cs" />
<Compile Include="ServiceImplementations\Log.cs" />
- <Compile Include="ServiceImplementations\log4netLogger.cs" />
+ <Compile Include="ServiceImplementations\Log4NetWrapper.cs" />
<Compile Include="ServiceImplementations\LogImpl.cs" />
<Compile Include="Services\GlobalServiceProvider.cs" />
<Compile Include="Services\ILog.cs" />
@@ -219,6 +219,12 @@
<Isolated>False</Isolated>
</COMReference>
</ItemGroup>
+ <ItemGroup>
+ <ProjectReference Include="..\..\Common-MP-TVE3\Common.Utils\Common.Utils.csproj">
+ <Project>{F6EDA1F3-3DCD-43F4-8A90-E32DA70C8227}</Project>
+ <Name>Common.Utils</Name>
+ </ProjectReference>
+ </ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<PropertyGroup>
<PreBuildEvent>
View
4 mediaportal/WatchDog/PostTestActions.cs
@@ -78,7 +78,7 @@ private void CreateHTMLIndexFile()
sw.WriteLine("<ul>");
sw.WriteLine("<li><a href=MediaPortal.log>MediaPortal.log</a></li>");
sw.WriteLine("<li><a href=Configuration.log>Configuration.log</a></li>");
- sw.WriteLine("<li><a href=Error.log>Error.log</a></li>");
+ sw.WriteLine("<li><a href=MediaPortal-Error.log>MediaPortal-Error.log</a></li>");
sw.WriteLine("<li><a href=Recorder.log>Recorder.log</a></li>");
if (File.Exists(_tmpDir + "\\TsReader.log"))
{
@@ -93,7 +93,7 @@ private void CreateHTMLIndexFile()
sw.WriteLine("<ul>");
sw.WriteLine("<li><a href=tvserver_tv.log>TV.log</a></li>");
sw.WriteLine("<li><a href=tvserver_epg.log>EPG.log</a></li>");
- sw.WriteLine("<li><a href=tvserver_error.log>Error.log</a></li>");
+ sw.WriteLine("<li><a href=tvserver_error.log>TV-Error.log</a></li>");
sw.WriteLine("<li><a href=tvserver_Streaming Server.log>Streaming Server.log</a></li>");
sw.WriteLine("<li><a href=tvserver_TsWriter.log>TsWriter.log</a></li>");
sw.WriteLine("<li><a href=tvserver_Player.log>Player.log</a></li>");

0 comments on commit 03e4d9c

Please sign in to comment.
Something went wrong with that request. Please try again.