Skip to content

Commit 418eceb

Browse files
committed
Add some more verbose logging
1 parent d5a6ed9 commit 418eceb

5 files changed

Lines changed: 41 additions & 15 deletions

File tree

Source/ExcelDna.Integration/AssemblyLoader.cs

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,8 @@ public static void ProcessAssemblies(
5858

5959
foreach (ExportedAssembly assembly in assemblies)
6060
{
61+
Logger.Initialization.Verbose("Processing assembly {0}. ExplicitExports {1}, ExplicitRegistration {2}, ComServer {3}, IsDynamic {4}",
62+
assembly.Assembly.FullName, assembly.ExplicitExports, assembly.ExplicitRegistration, assembly.ComServer, assembly.IsDynamic);
6163
// Patch contributed by y_i on CodePlex:
6264
// http://stackoverflow.com/questions/11915389/assembly-gettypes-throwing-an-exception
6365
Type[] types;
@@ -80,6 +82,8 @@ public static void ProcessAssemblies(
8082
foreach (Type type in types)
8183
{
8284
if (type == null) continue; // We might get nulls from ReflectionTypeLoadException above
85+
86+
Logger.Initialization.Verbose("Processing type {0}", type.FullName);
8387
try
8488
{
8589
object[] attribs = type.GetCustomAttributes(false);
@@ -96,12 +100,11 @@ public static void ProcessAssemblies(
96100
}
97101
catch (Exception e)
98102
{
99-
// TODO: This is unexpected - raise to LogDisplay?
100-
Debug.Print("Type {0} could not be analysed. Error: {1}", type.FullName, e.ToString());
103+
Logger.Initialization.Warn("Type {0} could not be processed. Error: {1}", type.FullName, e.ToString());
101104
}
102105
}
103106
}
104-
// Sigh. Excel server (service?) stuff is till ugly - but no reeal reason to remove it yet.
107+
// Sigh. Excel server (service?) stuff is still ugly - but no real reason to remove it yet.
105108
AssemblyLoaderExcelServer.GetExcelServerMethods(excelServerInfos, methods);
106109
}
107110

@@ -117,7 +120,7 @@ static void GetExcelMethods(Type t, bool explicitExports, List<MethodInfo> excel
117120
t.Namespace == "My")
118121
{
119122
// Ignored cases
120-
Logger.Registration.Info("Type ignored: {0}", t.FullName);
123+
Logger.Initialization.Info("Type ignored: {0}", t.FullName);
121124
return;
122125
}
123126

@@ -161,12 +164,12 @@ static bool IsMethodSupported(MethodInfo mi, bool explicitExports)
161164
// We want to log methods that are marked for export, but have unsupported types.
162165
if (!isSupported && IsMethodMarkedForExport(mi))
163166
{
164-
Logger.Registration.Error("Method not registered - unsupported types: '{0}.{1}'", mi.DeclaringType.Name, mi.Name);
167+
Logger.Initialization.Error("Method not registered - unsupported signature, abstract or generic: '{0}.{1}'", mi.DeclaringType.Name, mi.Name);
165168
}
166169
else if (!isSupported)
167170
{
168171
// CONSIDER: More detailed logging
169-
Logger.Registration.Info("Method not registered - unsupported types: '{0}.{1}'", mi.DeclaringType.Name, mi.Name);
172+
Logger.Initialization.Info("Method not registered - unsupported signature, abstract or generic: '{0}.{1}'", mi.DeclaringType.Name, mi.Name);
170173
}
171174

172175
return isSupported;
@@ -246,11 +249,12 @@ static public void GetExcelAddIns(ExportedAssembly assembly, Type t, bool loadRi
246249
info.Instance = Activator.CreateInstance(t);
247250
info.ParentDnaLibrary = assembly.ParentDnaLibrary;
248251
addIns.Add(info);
252+
Logger.Registration.Verbose("GetExcelAddIns - Created add-in object of type: {0}", t.FullName);
249253
}
250254
}
251255
catch (Exception e) // I think only CreateInstance can throw an exception here...
252256
{
253-
Debug.Print("GetExcelAddIns CreateInstance problem for type: {0} - exception: {1}", t.FullName, e);
257+
Logger.Initialization.Warn("GetExcelAddIns CreateInstance problem for type: {0} - exception: {1}", t.FullName, e);
254258
}
255259

256260
}
@@ -277,6 +281,7 @@ static public void GetRtdServerTypes(Type t, List<Type> rtdServerTypes, out bool
277281
//rtdServerTypes[t.FullName] = t;
278282
rtdServerTypes.Add(t);
279283
isRtdServer = true;
284+
Logger.Initialization.Verbose("GetRtdServerTypes - Found RTD server type: {0}", t.FullName);
280285
}
281286
}
282287
}
@@ -333,6 +338,7 @@ static public void GetComClassTypes(ExportedAssembly assembly, Type type, object
333338
TypeLibPath = assembly.TypeLibPath
334339
};
335340
comClassTypes.Add(comClassType);
341+
Logger.Initialization.Verbose("GetComClassTypes - Found type {0}, with ProgId {1}", type.FullName, progId);
336342
}
337343
}
338344

Source/ExcelDna.Integration/DnaLibrary.cs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,7 @@ internal List<ExportedAssembly> GetAssemblies(string pathResolveRoot)
245245
// TODO: Check that the registration calls we make in SyncContext.Install are safe in the COM Server context!?
246246
internal void Initialize()
247247
{
248+
Logger.Initialization.Verbose("{0} - Begin Initialize", Name);
248249
// Get MethodsInfos and AddIn classes from assemblies
249250
List<Type> rtdServerTypes = new List<Type>();
250251
List<ExcelComClassType> comClassTypes = new List<ExcelComClassType>();
@@ -253,7 +254,7 @@ internal void Initialize()
253254
_exportedAssemblies = GetAssemblies(dnaResolveRoot);
254255
AssemblyLoader.ProcessAssemblies(_exportedAssemblies, _methods, _addIns, rtdServerTypes, comClassTypes);
255256

256-
// Register RTD Server Types immediately
257+
// Register RTD Server Types (i.e. remember that these types are available as RTD servers, with relevant ProgId etc.)
257258
RtdRegistration.RegisterRtdServerTypes(rtdServerTypes);
258259

259260
// CAREFUL: This interacts with the implementation of ExcelRtdServer to implement the thread-safe synchronization.
@@ -268,10 +269,14 @@ internal void Initialize()
268269
break;
269270
}
270271
}
271-
if (registerSyncManager) SynchronizationManager.Install(); // TODO: Careful here!?
272+
if (registerSyncManager)
273+
{
274+
SynchronizationManager.Install(); // TODO: Careful here!?
275+
}
272276

273277
// Register COM Server Types immediately
274278
ComServer.RegisterComClassTypes(comClassTypes);
279+
Logger.Initialization.Verbose("{0} - End Initialize", Name);
275280
}
276281

277282
// Only called for the Root DnaLibrary.
@@ -305,6 +310,7 @@ internal void AutoOpen()
305310

306311
internal void AutoClose()
307312
{
313+
Logger.Initialization.Verbose("DnaLibrary AutoClose");
308314
UnloadCustomUI();
309315

310316
foreach (AssemblyLoader.ExcelAddInInfo addIn in _addIns)

Source/ExcelDna.Integration/ExcelRtd.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,13 @@ public static void RegisterRtdServerTypes(IEnumerable<Type> rtdServerTypes)
7070
{
7171
ProgIdAttribute progIdAtt = (ProgIdAttribute)attrs[0];
7272
registeredRtdServerTypes[progIdAtt.Value] = rtdType;
73+
Logger.Initialization.Verbose("RTD Server found - Type {0}, ProgId {1}", rtdType.FullName, progIdAtt.Value);
74+
}
75+
else
76+
{
77+
registeredRtdServerTypes[rtdType.FullName] = rtdType;
78+
Logger.Initialization.Verbose("RTD Server found - Type {0} (No ProgId)", rtdType.FullName);
7379
}
74-
registeredRtdServerTypes[rtdType.FullName] = rtdType;
7580
}
7681
}
7782

Source/ExcelDna.Integration/ExcelSynchronizationContext.cs

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,18 +60,27 @@ internal static class SynchronizationManager
6060
// Called from the Initialize (loading COM /RTD server) and/or from AutoOpen
6161
internal static void Install()
6262
{
63-
Debug.Assert(ExcelDnaUtil.IsMainThread, "SynchronizationManager must be Installed from the main Excel thread.");
63+
if (!ExcelDnaUtil.IsMainThread)
64+
{
65+
Logger.Initialization.Error("SynchronizationManager must be Installed from the main Excel thread.");
66+
return;
67+
}
6468
if (_syncWindow == null)
6569
{
70+
Logger.Initialization.Info("SynchronizationManager - Install");
6671
_syncWindow = new SynchronizationWindow();
6772
}
6873
}
6974

7075
internal static void Uninstall()
7176
{
72-
Debug.Assert(ExcelDnaUtil.IsMainThread, "SynchronizationManager must be Uninstalled from the main Excel thread.");
73-
_syncWindow.Dispose();
74-
_syncWindow = null;
77+
if (_syncWindow != null)
78+
{
79+
Logger.Initialization.Info("SynchronizationManager - Uninstall");
80+
Debug.Assert(ExcelDnaUtil.IsMainThread, "SynchronizationManager must be Uninstalled from the main Excel thread.");
81+
_syncWindow.Dispose();
82+
_syncWindow = null;
83+
}
7584
}
7685

7786
internal static bool IsInstalled

Source/ExcelDna.Loader/XlRegistration.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ public static object GetRegistrationInfo(object param)
112112
static void Register(List<MethodInfo> methods, List<object> targets, List<object> methodAttributes, List<List<object>> argumentAttributes)
113113
{
114114
Debug.Assert(targets == null || targets.Count == methods.Count);
115-
115+
Logger.Registration.Verbose("Registering {0} methods", methods.Count);
116116
List<XlMethodInfo> xlMethods = XlMethodInfo.ConvertToXlMethodInfos(methods, targets, methodAttributes, argumentAttributes);
117117
xlMethods.ForEach(RegisterXlMethod);
118118
// Increment the registration version (safe to call a few times)

0 commit comments

Comments
 (0)