Skip to content

Commit e8b8d6d

Browse files
committed
Further trace logging & update Distribution
1 parent 275a2f5 commit e8b8d6d

28 files changed

+276
-182
lines changed

Distribution/ChangeLog.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ Version 0.33 (???)
1313
* Fix integer return type with IsExceptionSafe=true crashes in marshaling.
1414
* Update ExcelReference to allow immutable use, mark AddRectangle mutator Obsolete. Add operator== to AsyncCallInfo.
1515
* Increase number of exports to 10,000.
16+
* Implement logging mechanism based on System.Diagnostics.Trace.
1617

1718
Version 0.32 (3 May 2014)
1819
-------------------------
7.5 KB
Binary file not shown.

Distribution/ExcelDna.xll

12.5 KB
Binary file not shown.

Distribution/ExcelDna64.xll

12.5 KB
Binary file not shown.

Distribution/ExcelDnaPack.exe

0 Bytes
Binary file not shown.

Source/ExcelDna.Integration/AssemblyLoader.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ static void GetExcelMethods(Type t, bool explicitExports, List<MethodInfo> excel
117117
t.Namespace == "My")
118118
{
119119
// Ignored cases
120-
RegistrationLogger.Info("Type ignored: {0}", t.FullName);
120+
Logger.Registration.Info("Type ignored: {0}", t.FullName);
121121
return;
122122
}
123123

@@ -161,12 +161,12 @@ static bool IsMethodSupported(MethodInfo mi, bool explicitExports)
161161
// We want to log methods that are marked for export, but have unsupported types.
162162
if (!isSupported && IsMethodMarkedForExport(mi))
163163
{
164-
RegistrationLogger.Error("Method not registered - unsupported types: '{0}.{1}'", mi.DeclaringType.Name, mi.Name);
164+
Logger.Registration.Error("Method not registered - unsupported types: '{0}.{1}'", mi.DeclaringType.Name, mi.Name);
165165
}
166166
else if (!isSupported)
167167
{
168168
// CONSIDER: More detailed logging
169-
RegistrationLogger.Info("Method not registered - unsupported types: '{0}.{1}'", mi.DeclaringType.Name, mi.Name);
169+
Logger.Registration.Info("Method not registered - unsupported types: '{0}.{1}'", mi.DeclaringType.Name, mi.Name);
170170
}
171171

172172
return isSupported;

Source/ExcelDna.Integration/ComRegistration.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ Govert van Drimmelen
2323
*/
2424

2525
using System;
26-
using System.Diagnostics;
2726
using System.Runtime.InteropServices;
2827
using System.Security;
2928
using Microsoft.Win32;
@@ -35,6 +34,7 @@ Govert van Drimmelen
3534
using DWORD = System.Int32;
3635
using HRESULT = System.Int32;
3736
using IID = System.Guid;
37+
using ExcelDna.Logging;
3838

3939
namespace ExcelDna.ComInterop.ComRegistration
4040
{
@@ -193,7 +193,7 @@ static bool CanWriteMachineHive()
193193
RegistryKey testKey = Registry.ClassesRoot.CreateSubKey(testKeyName, RegistryKeyPermissionCheck.ReadWriteSubTree);
194194
if (testKey == null)
195195
{
196-
Debug.Print("Unexpected failure in CanWriteMachineHive check");
196+
Logger.ComAddIn.Error("Unexpected failure in CanWriteMachineHive check");
197197
return false;
198198
}
199199
else
@@ -215,7 +215,7 @@ static bool CanWriteMachineHive()
215215
}
216216
catch (Exception e)
217217
{
218-
Debug.Print("Unexpected exception in CanWriteMachineHive check: " + e);
218+
Logger.ComAddIn.Error(e, "Unexpected exception in CanWriteMachineHive check");
219219
return false;
220220
}
221221
}

Source/ExcelDna.Integration/DnaLibrary.cs

Lines changed: 25 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ Govert van Drimmelen
2424

2525
using System;
2626
using System.Collections.Generic;
27-
using System.Diagnostics;
2827
using System.IO;
2928
using System.Reflection;
3029
using System.Runtime.InteropServices;
@@ -37,6 +36,7 @@ Govert van Drimmelen
3736
using ExcelDna.Integration.CustomUI;
3837
using ExcelDna.Integration.Rtd;
3938
using ExcelDna.ComInterop;
39+
using ExcelDna.Logging;
4040

4141
namespace ExcelDna.Integration
4242
{
@@ -222,8 +222,8 @@ internal List<ExportedAssembly> GetAssemblies(string pathResolveRoot)
222222
}
223223
catch (Exception e)
224224
{
225-
Logging.LogDisplay.WriteLine("There was an error in loading the add-in " + DnaLibrary.CurrentLibraryName + " (" + DnaLibrary.XllPath + "):");
226-
Logging.LogDisplay.WriteLine("Error in loading assemblies. Exception: " + e.ToString());
225+
Logger.Initialization.Error("There was an error in loading the add-in " + DnaLibrary.CurrentLibraryName + " (" + DnaLibrary.XllPath + "):");
226+
Logger.Initialization.Error(e, "Error in loading assemblies");
227227
}
228228
return assemblies;
229229
}
@@ -296,7 +296,7 @@ internal void AutoOpen()
296296
catch (Exception e)
297297
{
298298
// TODO: What to do here?
299-
Debug.Print(e.Message);
299+
Logger.Initialization.Error(e, "DnaLibrary AutoOpen Error");
300300
}
301301
}
302302

@@ -318,8 +318,7 @@ internal void AutoClose()
318318
}
319319
catch (Exception e)
320320
{
321-
// TODO: What to do here?
322-
Debug.WriteLine(e.Message);
321+
Logger.Initialization.Warn("DnaLibrary AutoClose Error: {0}", e.Message);
323322
}
324323
}
325324
// This is safe, even if never registered
@@ -414,20 +413,21 @@ internal static void InitializeRootLibrary(string xllPath)
414413
// 1. Look for a packed .dna file named "__MAIN__" in the .xll.
415414
// 2. Look for the .dna file in the same directory as the .xll file, with the same name and extension .dna.
416415

417-
Debug.WriteLine("Enter DnaLibrary.InitializeRootLibrary");
416+
// CAREFUL: Sequence here is fragile - this is the first place where we start logging
418417
_XllPath = xllPath;
419418
Logging.LogDisplay.CreateInstance();
419+
Logger.Initialization.Verbose("Enter DnaLibrary.InitializeRootLibrary");
420420
byte[] dnaBytes = ExcelIntegration.GetDnaFileBytes("__MAIN__");
421421
if (dnaBytes != null)
422422
{
423-
Debug.WriteLine("Got Dna file from resources.");
423+
Logger.Initialization.Verbose("Got Dna file from resources.");
424424
string pathResolveRoot = Path.GetDirectoryName(DnaLibrary.XllPath);
425425
rootLibrary = LoadFrom(dnaBytes, pathResolveRoot);
426426
// ... would have displayed error and returned null if there was an error.
427427
}
428428
else
429429
{
430-
Debug.WriteLine("No Dna file in resources - looking for file.");
430+
Logger.Initialization.Verbose("No Dna file in resources - looking for file.");
431431
// No packed .dna file found - load from a .dna file.
432432
string dnaFileName = Path.ChangeExtension(XllPath, ".dna");
433433
rootLibrary = LoadFrom(dnaFileName);
@@ -437,12 +437,12 @@ internal static void InitializeRootLibrary(string xllPath)
437437
// If there have been problems, ensure that there is at lease some current library.
438438
if (rootLibrary == null)
439439
{
440-
Debug.WriteLine("No Dna Library found.");
440+
Logger.Initialization.Error("No Dna Library found.");
441441
rootLibrary = new DnaLibrary();
442442
}
443443

444444
rootLibrary.Initialize();
445-
Debug.WriteLine("Exit DnaLibrary.Initialize");
445+
Logger.Initialization.Verbose("Exit DnaLibrary.Initialize");
446446
}
447447

448448
internal static void DeInitialize()
@@ -467,9 +467,7 @@ public static DnaLibrary LoadFrom(Uri uri)
467467
}
468468
catch (Exception e)
469469
{
470-
string errorMessage = string.Format("There was an error in loading the .dna file from a Uri:\r\n{0}\r\n{1}\r\nUri:{2}", e.Message, e.InnerException != null ? e.InnerException.Message : string.Empty, uri.ToString());
471-
Debug.WriteLine(errorMessage);
472-
ExcelDna.Logging.LogDisplay.WriteLine(errorMessage);
470+
Logger.Initialization.Error("There was an error in loading the .dna file from a Uri:\r\n{0}\r\n{1}\r\nUri:{2}", e.Message, e.InnerException != null ? e.InnerException.Message : string.Empty, uri.ToString());
473471
return null;
474472
}
475473

@@ -492,9 +490,7 @@ public static DnaLibrary LoadFrom(byte[] bytes, string pathResolveRoot)
492490
}
493491
catch (Exception e)
494492
{
495-
string errorMessage = string.Format("There was an error in processing .dna file bytes:\r\n{0}\r\n{1}", e.Message, e.InnerException != null ? e.InnerException.Message : string.Empty);
496-
Debug.WriteLine(errorMessage);
497-
//ExcelDna.Logging.LogDisplay.SetText(errorMessage);
493+
Logger.Initialization.Error("There was an error in processing .dna file bytes:\r\n{0}\r\n{1}", e.Message, e.InnerException != null ? e.InnerException.Message : string.Empty);
498494
return null;
499495
}
500496
dnaLibrary.dnaResolveRoot = pathResolveRoot;
@@ -507,7 +503,7 @@ public static DnaLibrary LoadFrom(string fileName)
507503

508504
if (!File.Exists(fileName))
509505
{
510-
ExcelDna.Logging.LogDisplay.WriteLine("The required .dna script file {0} does not exist.", fileName);
506+
Logger.Initialization.Error("The required .dna script file {0} does not exist.", fileName);
511507
return null;
512508
}
513509

@@ -521,7 +517,7 @@ public static DnaLibrary LoadFrom(string fileName)
521517
}
522518
catch (Exception e)
523519
{
524-
ExcelDna.Logging.LogDisplay.WriteLine("There was an error during processing of {0}:\r\n{1}\r\n{2}", fileName, e.Message, e.InnerException != null ? e.InnerException.Message : string.Empty);
520+
Logger.Initialization.Error("There was an error during processing of {0}:\r\n{1}\r\n{2}", fileName, e.Message, e.InnerException != null ? e.InnerException.Message : string.Empty);
525521
return null;
526522
}
527523
dnaLibrary.dnaResolveRoot = Path.GetDirectoryName(fileName);
@@ -602,11 +598,11 @@ public string ResolvePath(string path)
602598
public static string ResolvePath(string path, string dnaDirectory)
603599
{
604600

605-
Debug.Print("ResolvePath: Resolving {0} from DnaDirectory: {1}", path, dnaDirectory);
601+
Logger.Initialization.Info("ResolvePath: Resolving {0} from DnaDirectory: {1}", path, dnaDirectory);
606602
if (File.Exists(path))
607603
{
608604
string fullPath = Path.GetFullPath(path);
609-
Debug.Print("ResolvePath: Found at {0}", fullPath);
605+
Logger.Initialization.Info("ResolvePath: Found at {0}", fullPath);
610606
return fullPath;
611607
}
612608

@@ -625,10 +621,10 @@ public static string ResolvePath(string path, string dnaDirectory)
625621
// Not rooted - try a path relative to local directory
626622
dnaPath = System.IO.Path.Combine(dnaDirectory, path);
627623
}
628-
Debug.Print("ResolvePath: Checking at {0}", dnaPath);
624+
Logger.Initialization.Verbose("ResolvePath: Checking at {0}", dnaPath);
629625
if (File.Exists(dnaPath))
630626
{
631-
Debug.Print("ResolvePath: Found at {0}", dnaPath);
627+
Logger.Initialization.Info("ResolvePath: Found at {0}", dnaPath);
632628
return dnaPath;
633629
}
634630
}
@@ -646,10 +642,10 @@ public static string ResolvePath(string path, string dnaDirectory)
646642
basePath = System.IO.Path.Combine(baseDirectory, path);
647643
}
648644
// ... and check again
649-
Debug.Print("ResolvePath: Checking at {0}", basePath);
645+
Logger.Initialization.Verbose("ResolvePath: Checking at {0}", basePath);
650646
if (File.Exists(basePath))
651647
{
652-
Debug.Print("ResolvePath: Found at {0}", basePath);
648+
Logger.Initialization.Info("ResolvePath: Found at {0}", basePath);
653649
return basePath;
654650
}
655651
}
@@ -662,12 +658,12 @@ public static string ResolvePath(string path, string dnaDirectory)
662658
string frameworkPath = Path.Combine(frameworkBase, fileName);
663659
if (File.Exists(frameworkPath))
664660
{
665-
Debug.Print("ResolvePath: Found at {0}", frameworkPath);
661+
Logger.Initialization.Info("ResolvePath: Found at {0}", frameworkPath);
666662
return frameworkPath;
667663
}
668664

669665
// Else give up (maybe try load from GAC for assemblies?)
670-
Debug.Print("ResolvePath: Could not find {0} from DnaDirectory {1}", path, dnaDirectory);
666+
Logger.Initialization.Error("ResolvePath: Could not find {0} from DnaDirectory {1}", path, dnaDirectory);
671667
return null;
672668
}
673669

@@ -694,7 +690,7 @@ public Bitmap GetImage(string imageId)
694690
if (imagePath == null)
695691
{
696692
// This is the image but we could not find it !?
697-
Debug.Print("DnaLibrary.LoadImage - For image {0} the path resolution failed: {1}", image.Name, image.Path);
693+
Logger.Initialization.Warn("DnaLibrary.GetImage - For image {0} the path resolution failed: {1}", image.Name, image.Path);
698694
return null;
699695
}
700696
imageBytes = File.ReadAllBytes(imagePath);
@@ -706,7 +702,7 @@ public Bitmap GetImage(string imageId)
706702
{
707703
return (Bitmap)imageLoaded;
708704
}
709-
Debug.Print("Image {0} read from {1} was not a bitmap!?", image.Name, image.Path);
705+
Logger.Initialization.Warn("DnaLibrary.GetImage - Image {0} read from {1} was not a bitmap!?", image.Name, image.Path);
710706
}
711707
}
712708
}

Source/ExcelDna.Integration/ExcelComAddIn.cs

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
using System;
22
using System.Collections.Generic;
3-
using System.Diagnostics;
43
using System.Globalization;
54
using System.Reflection;
65
using System.Runtime.InteropServices;
76
using ExcelDna.ComInterop.ComRegistration;
87
using ExcelDna.Integration.CustomUI;
98
using ExcelDna.Integration.Extensibility;
9+
using ExcelDna.Logging;
1010

1111
namespace ExcelDna.Integration
1212
{
@@ -29,27 +29,27 @@ internal void SetProgId(string progId)
2929
#region IDTExtensibility2 interface
3030
public virtual void OnConnection(object Application, ext_ConnectMode ConnectMode, object AddInInst, ref Array custom)
3131
{
32-
Debug.Print("ExcelComAddIn.OnConnection");
32+
Logger.ComAddIn.Verbose("ExcelComAddIn.OnConnection");
3333
}
3434

3535
public virtual void OnDisconnection(ext_DisconnectMode RemoveMode, ref Array custom)
3636
{
37-
Debug.Print("ExcelComAddIn.OnDisconnection");
37+
Logger.ComAddIn.Verbose("ExcelComAddIn.OnDisconnection");
3838
}
3939

4040
public virtual void OnAddInsUpdate(ref Array custom)
4141
{
42-
Debug.Print("ExcelComAddIn.OnAddInsUpdate");
42+
Logger.ComAddIn.Verbose("ExcelComAddIn.OnAddInsUpdate");
4343
}
4444

4545
public virtual void OnStartupComplete(ref Array custom)
4646
{
47-
Debug.Print("ExcelComAddIn.OnStartupComplete");
47+
Logger.ComAddIn.Verbose("ExcelComAddIn.OnStartupComplete");
4848
}
4949

5050
public virtual void OnBeginShutdown(ref Array custom)
5151
{
52-
Debug.Print("ExcelComAddIn.OnBeginShutdown");
52+
Logger.ComAddIn.Verbose("ExcelComAddIn.OnBeginShutdown");
5353
}
5454
#endregion
5555
}
@@ -100,10 +100,10 @@ public static void LoadComAddIn(ExcelComAddIn addIn)
100100
string description = string.Format("Dynamically created COM Add-in to load custom UI for the Excel Add-in {0}, located at {1}.", addIn.DnaLibrary.Name, DnaLibrary.XllPath);
101101

102102

103-
Debug.Print("Getting Application object");
103+
Logger.ComAddIn.Verbose("Getting Application object");
104104
object app = ExcelDnaUtil.Application;
105105
Type appType = app.GetType();
106-
Debug.Print("Got Application object: " + app.GetType().ToString());
106+
Logger.ComAddIn.Verbose("Got Application object: " + app.GetType().ToString());
107107

108108
CultureInfo ci = new CultureInfo(1033);
109109
object excelComAddIns;
@@ -134,8 +134,7 @@ public static void LoadComAddIn(ExcelComAddIn addIn)
134134
}
135135
catch (UnauthorizedAccessException secex)
136136
{
137-
Logging.LogDisplay.WriteLine("The Ribbon/COM Add-in helper required by add-in {0} could not be registered.\r\nThis may be due to restricted permissions on the user's HKCU\\Software\\Classes key.\r\nError message: {1}", DnaLibrary.CurrentLibrary.Name, secex.Message);
138-
Debug.Print("LoadComAddIn exception: " + secex.ToString());
137+
Logger.ComAddIn.Error(secex, "The Ribbon/COM add-in helper required by add-in {0} could not be registered.\r\nThis may be due to restricted permissions on the user's HKCU\\Software\\Classes key.", DnaLibrary.CurrentLibrary.Name);
139138
}
140139
catch (Exception ex)
141140
{
@@ -145,9 +144,9 @@ public static void LoadComAddIn(ExcelComAddIn addIn)
145144
// CONSIDER: How would an add-in know that its COM AddIn load failed in this case?
146145
if (!Environment.CommandLine.Contains(" /K"))
147146
{
148-
Logging.LogDisplay.WriteLine("The Ribbon/COM Add-in helper required by add-in {0} could not be registered.\r\nThis is an unexpected error.\r\nError message: {1}", DnaLibrary.CurrentLibrary.Name, ex.Message);
147+
Logger.ComAddIn.Error("The Ribbon/COM add-in helper required by add-in {0} could not be registered.\r\nThis is an unexpected error.", DnaLibrary.CurrentLibrary.Name);
149148
}
150-
Debug.Print("LoadComAddIn exception: " + ex.ToString());
149+
Logger.ComAddIn.Info("LoadComAddIn exception: {0} with /K in CommandLine", ex.ToString());
151150
}
152151
}
153152

@@ -157,7 +156,7 @@ internal static void UnloadComAddIns()
157156
foreach (object comAddIn in loadedComAddIns)
158157
{
159158
comAddIn.GetType().InvokeMember("Connect", System.Reflection.BindingFlags.SetProperty, null, comAddIn, new object[] { false }, ci);
160-
Debug.Print("COMAddin is unloaded.");
159+
Logger.ComAddIn.Info("COMAddin is unloaded.");
161160
}
162161
}
163162
}

Source/ExcelDna.Integration/ExcelIntegration.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ Govert van Drimmelen
3030
namespace ExcelDna.Integration
3131
{
3232
using ExcelDna.ComInterop;
33+
using ExcelDna.Logging;
3334
using HRESULT = Int32;
3435

3536
// CAUTION: These functions are called _via reflection_ by
@@ -233,16 +234,16 @@ internal static void DeInitialize()
233234

234235
internal static void DnaLibraryAutoOpen()
235236
{
236-
Debug.WriteLine("Enter Integration.DnaLibraryAutoOpen");
237+
Logger.Initialization.Verbose("Enter Integration.DnaLibraryAutoOpen");
237238
try
238239
{
239240
DnaLibrary.CurrentLibrary.AutoOpen();
240241
}
241242
catch (Exception e)
242243
{
243-
Debug.WriteLine("Integration.DnaLibraryAutoOpen Exception: " + e);
244+
Logger.Initialization.Error(e, "Integration.DnaLibraryAutoOpen Error");
244245
}
245-
Debug.WriteLine("Exit Integration.DnaLibraryAutoOpen");
246+
Logger.Initialization.Verbose("Exit Integration.DnaLibraryAutoOpen");
246247
}
247248

248249
internal static void DnaLibraryAutoClose()

0 commit comments

Comments
 (0)