Make the service loader pump out the error to the log (in red) and include the dll/interface/args that caused the problem

This gives people more of a fighting chance of finding out what went wrong
slimupdates
Justin Clark-Casey (justincc) 2010-03-03 18:28:30 +00:00
parent 304c626824
commit 296c68a9de
2 changed files with 24 additions and 5 deletions

View File

@ -26,7 +26,9 @@
*/
using System;
using System.Collections.Generic;
using System.Reflection;
using log4net;
using Nini.Config;
using OpenSim.Services.Interfaces;
@ -34,6 +36,8 @@ namespace OpenSim.Services.Base
{
public class ServiceBase
{
private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
public T LoadPlugin<T>(string dllName) where T:class
{
return LoadPlugin<T>(dllName, new Object[0]);
@ -61,8 +65,12 @@ namespace OpenSim.Services.Base
{
Assembly pluginAssembly = Assembly.LoadFrom(dllName);
// m_log.DebugFormat("[SERVICE BASE]: Found assembly {0}", dllName);
foreach (Type pluginType in pluginAssembly.GetTypes())
{
// m_log.DebugFormat("[SERVICE BASE]: Found type {0}", pluginType);
if (pluginType.IsPublic)
{
if (className != String.Empty &&
@ -86,7 +94,15 @@ namespace OpenSim.Services.Base
}
catch (Exception e)
{
Console.WriteLine("XXX Exception " + e.StackTrace);
List<string> strArgs = new List<string>();
foreach (Object arg in args)
strArgs.Add(arg.ToString());
m_log.Error(
string.Format(
"[SERVICE BASE]: Failed to load plugin {0} from {1} with args {2}",
interfaceName, dllName, string.Join(", ", strArgs.ToArray())), e);
return null;
}
}
@ -95,4 +111,4 @@ namespace OpenSim.Services.Base
{
}
}
}
}

View File

@ -27,13 +27,12 @@
using System;
using System.Reflection;
using log4net;
using Nini.Config;
using OpenSim.Framework;
using OpenSim.Data;
using OpenSim.Services.Interfaces;
using OpenSim.Services.Base;
using Nini.Config;
using log4net;
namespace OpenSim.Services.Friends
{
@ -80,7 +79,11 @@ namespace OpenSim.Services.Friends
m_Database = LoadPlugin<IFriendsData>(dllName, new Object[] { connString, realm });
if (m_Database == null)
throw new Exception("Could not find a storage interface in the given module");
{
throw new Exception(
string.Format(
"Could not find a storage interface {0} in the given StorageProvider {1}", "IFriendsData", dllName));
}
}
}
}