Files
Sourcetrail/ide_plugins/vs/vs2015/SourcetrailPlugin/SourcetrailPluginUtility/Logging/VSOutputLogger.cs
T
malte_langkabel b659e81515 logic: fix more Visual Studio plugin issues
* using .Net framework version 4.6.1 in all projects
* implemented exception handling in VCFileWrapperFactory
* moved logging in separate assembly
* enabled logging in wrapper code
2017-06-06 15:46:14 +02:00

78 lines
1.8 KiB
C#

using EnvDTE;
using System;
using System.Diagnostics;
namespace CoatiSoftware.SourcetrailPlugin.Logging
{
public class VSOutputLogger : ILogger
{
private EnvDTE.DTE _dte = null;
private OutputWindowPane _pane = null;
public VSOutputLogger(EnvDTE.DTE dte)
{
_dte = dte;
}
public void LogMessage(LogMessage message)
{
if (message.MessageType == SourcetrailPlugin.Logging.LogMessage.LogMessageType.INFO)
{
Debug.WriteLine(message.Message, "Info");
WriteToOutputWindow("Info: " + message.Message);
}
if (message.MessageType == SourcetrailPlugin.Logging.LogMessage.LogMessageType.WARNING)
{
Debug.WriteLine(message.Message, "Warning");
WriteToOutputWindow("Warning: " + message.Message);
}
if (message.MessageType == SourcetrailPlugin.Logging.LogMessage.LogMessageType.ERROR)
{
Debug.WriteLine(message.Message, "Error");
WriteToOutputWindow("Error: " + message.Message);
}
}
private void WriteToOutputWindow(string message)
{
string paneName = "Sourcetrail Log";
if (_dte.Windows.Count > 0)
{
Window window = _dte.Windows.Item(EnvDTE.Constants.vsWindowKindOutput);
OutputWindow outputWindow = (OutputWindow)window.Object;
OutputWindowPanes panes = outputWindow.OutputWindowPanes;
if(_pane == null)
{
try
{
for (int i = 0; i < panes.Count; i++)
{
OutputWindowPane pane = panes.Item(i);
if (pane.Name.Equals(paneName, StringComparison.CurrentCultureIgnoreCase))
{
_pane = outputWindow.OutputWindowPanes.Item(i);
break;
}
}
}
catch (Exception e)
{
}
}
if (_pane == null)
{
_pane = outputWindow.OutputWindowPanes.Add(paneName);
}
_pane.OutputString(message + '\n');
}
}
}
}