Skip to content

Commit

Permalink
Merge pull request #89 from navferty/more-detailed-logs
Browse files Browse the repository at this point in the history
add more detailed logs in infrastructure methods (GetLabel, GetImage, GetSupertip). #83
  • Loading branch information
navferty authored Jul 13, 2021
2 parents 05e59b2 + 3b65598 commit b892b78
Showing 1 changed file with 50 additions and 4 deletions.
54 changes: 50 additions & 4 deletions NavfertyExcelAddIn/NavfertyRibbon.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
using System.Drawing;
using System.IO;
Expand Down Expand Up @@ -64,7 +65,13 @@ public class NavfertyRibbon : IRibbonExtensibility, IDisposable
#region IRibbonExtensibility
public string GetCustomUI(string ribbonID)
{
return GetResourceText();
var sw = Stopwatch.StartNew();
logger.Debug($"{nameof(GetCustomUI)} - {ribbonID}");

var customUiXml = GetResourceText();

logger.Debug($"{nameof(GetCustomUI)} got xml for {sw.Elapsed}");
return customUiXml;
}
#endregion

Expand Down Expand Up @@ -391,15 +398,54 @@ public void ValidateXml(IRibbonControl ribbonControl)
#region Utils
public string GetLabel(IRibbonControl ribbonControl)
{
return RibbonLabels.ResourceManager.GetString(ribbonControl.Id);
var sw = Stopwatch.StartNew();
logger.Debug($"{nameof(GetLabel)} - {ribbonControl?.Id}");
try
{
var label = RibbonLabels.ResourceManager.GetString(ribbonControl.Id);
logger.Debug($"{nameof(GetLabel)} - {ribbonControl?.Id}: '{label}'. Elapsed {sw.Elapsed}");
return label;
}
catch (Exception ex)
{
logger.Error($"{nameof(GetLabel)} - {ribbonControl?.Id} error after {sw.Elapsed}:");
logger.Error(ex);
return ribbonControl?.Id;
}
}
public Bitmap GetImage(string imageName)
{
return (Bitmap)RibbonIcons.ResourceManager.GetObject(imageName);
var sw = Stopwatch.StartNew();
logger.Debug($"{nameof(GetImage)} - {imageName}");
try
{
var bitmap = (Bitmap)RibbonIcons.ResourceManager.GetObject(imageName);
logger.Debug($"{nameof(GetImage)} - {imageName}: '{bitmap?.Size}'. Elapsed {sw.Elapsed}");
return bitmap;
}
catch (Exception ex)
{
logger.Error($"{nameof(GetImage)} - {imageName} error after {sw.Elapsed}:");
logger.Error(ex);
return null;
}
}
public string GetSupertip(IRibbonControl ribbonControl)
{
return RibbonSupertips.ResourceManager.GetString(ribbonControl.Id);
var sw = Stopwatch.StartNew();
logger.Debug($"{nameof(GetSupertip)} - {ribbonControl?.Id}");
try
{
var superTip = RibbonSupertips.ResourceManager.GetString(ribbonControl.Id);
logger.Debug($"{nameof(GetSupertip)} - {ribbonControl?.Id}: '{superTip}'. Elapsed {sw.Elapsed}");
return superTip;
}
catch (Exception ex)
{
logger.Error($"{nameof(GetSupertip)} - {ribbonControl?.Id} error after {sw.Elapsed}:");
logger.Error(ex);
return ribbonControl?.Id;
}
}

private T GetService<T>()
Expand Down

0 comments on commit b892b78

Please sign in to comment.