/// (c) 2007 James A Briant
///
/// Permission is granted to use or modify this source code provided that
/// a) this notice is kept intact
/// b) if you make any modications to this file you assign the
/// copyright of those modifications to James Briant.
/// c) you acknowledge that Mr. Briant offers no warranty
/// and will not be liable for any loss, damages, time, etc.
///
/// Any doubt, email me: firstname (nospace) lastname at persuasivesoftware.com
///
/// This package is inspired by Noel Llopis's P4AddIn (also available from
/// the perforce public depot), and also a similar package that I developed
/// at Bunkspeed, Inc ( www.bunkspeed.com ) makers of real-time raytracing
/// tools that anyone case use.
using System.Collections.Generic;
using Microsoft.VisualStudio.Shell.Interop;
namespace DevDriven.P4Vs
{
public interface ILogger
{
void WriteLine(int level, string format, params object[] args);
void Write(int level, string format, params object[] args);
}
class MultiLogger : ILogger
{
public void Add(ILogger logger)
{
loggers.Add(logger);
}
readonly List<ILogger> loggers = new List<ILogger>();
public void WriteLine(int level, string format, params object[] args)
{
foreach (ILogger logger in loggers)
{
logger.WriteLine(level, format, args);
}
}
#region ILogger Members
public void Write(int level, string format, params object[] args)
{
foreach (ILogger logger in loggers)
{
logger.Write(level, format, args);
}
}
#endregion
}
class OutputWindowLogger : ILogger
{
private readonly IVsOutputWindowPane outputPane;
private readonly int errorLevel;
private readonly bool activate;
public OutputWindowLogger(IVsOutputWindowPane outputPane, int errorLevel,bool activate)
{
this.outputPane = outputPane;
this.errorLevel = errorLevel;
this.activate = activate;
}
public void WriteLine( int level, string format, params object[] args)
{
if ( level >= errorLevel)
{
string s = string.Format(format, args);
outputPane.OutputString(s + "\n");
if (activate)
outputPane.Activate();
}
}
public void Write(int level, string format, params object[] args)
{
if (level >= errorLevel)
{
string s = string.Format(format, args);
outputPane.OutputString(s);
if (activate)
outputPane.Activate();
}
}
}
}