Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion XrmToolBox.Extensibility/LogManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,16 @@ public void LogInfo(string message, params object[] args)
Log(Level.Info, args.Length == 0 ? message : string.Format(message, args));
}

/// <summary>
/// Writes a verbose message in the log
/// </summary>
/// <param name="message"></param>
/// <param name="args"></param>
public void LogVerbose(string message, params object[] args)
{
Log(Level.Verbose, args.Length == 0 ? message : string.Format(message, args));
}

/// <summary>
/// Writes a warning message in the log
/// </summary>
Expand Down Expand Up @@ -112,6 +122,10 @@ public void SetConnection(ConnectionDetail connectionDetail)
/// <param name="message">Content of the message</param>
private void Log(Level level, string message)
{
if (LogLevel > level)
{ // No logging for this level since it's less than the settings level
return;
}
var parentFolder = Path.GetDirectoryName(_filePath);
if (parentFolder != null && !Directory.Exists(parentFolder))
{
Expand All @@ -124,7 +138,7 @@ private void Log(Level level, string message)
{
using (StreamWriter writer = new StreamWriter(_filePath, true))
{
writer.WriteLine("{0:yyyy-MM-dd hh:mm:ss.fff tt}\t{1}\t{2}\t{3}", DateTime.Now,
writer.WriteLine("{0:yyyy-MM-dd HH:mm:ss.fff}\t{1}\t{2}\t{3}", DateTime.Now,
_connection?.ConnectionName, level, message);
}
}
Expand Down
10 changes: 10 additions & 0 deletions XrmToolBox.Extensibility/PluginControlBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -390,6 +390,16 @@ public void LogInfo(string message, params object[] args)
logManager.LogInfo(message, args);
}

/// <summary>
/// Writes a verbose message in the log
/// </summary>
/// <param name="message"></param>
/// <param name="args"></param>
public void LogVerbose(string message, params object[] args)
{
logManager.LogVerbose(message, args);
}

/// <summary>
/// Writes a warning message in the log
/// </summary>
Expand Down
19 changes: 18 additions & 1 deletion XrmToolBox/AppCode/AppInsights/AppInsights.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@
using System.Reflection;
using System.Runtime.Serialization;
using System.Runtime.Serialization.Json;
using System.Text;
using XrmToolBox.AppCode.AppInsights;
using XrmToolBox.Extensibility;

public static class Extensions
{
Expand Down Expand Up @@ -82,6 +82,7 @@ private static string GetLastDotPart(string identifier)

public class AppInsights
{
private readonly PluginControlBase _tool;
private readonly AiConfig _aiConfig;
private int seq = 1;

Expand All @@ -93,6 +94,21 @@ public class AppInsights
/// <param name="ikey">Instrumentation Key for the AppInsights instance in the Azure portal</param>
/// <param name="loggingassembly">Assembly info to include in logging, usually pass Assembly.GetExecutingAssembly()</param>
/// <param name="toolname">Override name of the tool, defaults to last part of the logging assembly name</param>
public AppInsights(PluginControlBase tool, string endpoint, string ikey, Assembly loggingassembly, string toolname = null)
{
_tool = tool;
_aiConfig = new AiConfig(endpoint, ikey, loggingassembly, toolname);
}

/// <summary>
/// Initializes Application Insights instance.
/// When called from a tool, make sure to pass Assembly.GetExecutingAssembly() as loggingassembly parameter!!
/// </summary>
/// <param name="endpoint">AppInsights endpoint, usually https://dc.services.visualstudio.com/v2/track</param>
/// <param name="ikey">Instrumentation Key for the AppInsights instance in the Azure portal</param>
/// <param name="loggingassembly">Assembly info to include in logging, usually pass Assembly.GetExecutingAssembly()</param>
/// <param name="toolname">Override name of the tool, defaults to last part of the logging assembly name</param>
[Obsolete("Use constructor accepting PluginControlBase tool, endpoint, ikey, loggingassembly and toolname instead.", false)]
public AppInsights(string endpoint, string ikey, Assembly loggingassembly, string toolname = null)
{
_aiConfig = new AiConfig(endpoint, ikey, loggingassembly, toolname);
Expand All @@ -110,6 +126,7 @@ public AppInsights(AiConfig aiConfig)

public void WriteEvent(string eventName, double? count = null, double? duration = null, Action<string> resultHandler = null)
{
_tool?.LogVerbose($"{eventName}{(count != null ? $" Count: {count}" : "")}{(duration != null ? $" Duration: {duration}" : "")}");
if (!_aiConfig.LogEvents) return;
var logRequest = GetLogRequest("Event");
logRequest.Data.BaseData.Name = eventName;
Expand Down