using System;
namespace SharpGen.Logging
{
public abstract class LoggerBase
{
///
/// Gets or sets the logger output.
///
/// The logger output.
public abstract ILogger LoggerOutput { get; }
///
/// Gets a value indicating whether this instance has errors.
///
///
/// true if this instance has errors; otherwise, false.
///
public abstract bool HasErrors { get; }
///
/// Gets or sets the progress report.
///
/// The progress report.
public abstract IProgressReport ProgressReport { get; }
///
/// Runs a delegate in the specified log context.
///
/// The context.
/// The method.
public void RunInContext(string context, Action method)
{
try
{
PushContext(context);
method();
}
finally
{
PopContext();
}
}
///
/// Pushes a context string.
///
/// The context.
public abstract void PushContext(string context);
///
/// Pushes a context location.
///
/// Name of the file.
/// The line.
/// The column.
public abstract void PushLocation(string fileName, int line = 1, int column = 1);
///
/// Pops the context location.
///
public abstract void PopLocation();
///
/// Pushes a context formatted string.
///
/// The context.
/// The parameters.
public abstract void PushContext(string context, params object[] parameters);
///
/// Pops the context.
///
public abstract void PopContext();
///
/// Logs the specified message.
///
/// The message.
public void Message(string message)
{
Message("{0}", message);
}
///
/// Logs the specified message.
///
/// The message.
/// The parameters.
public void Message(string message, params object[] parameters)
{
LogRawMessage(LogLevel.Info, null, message, null, parameters);
}
///
/// Logs the specified progress level and message.
///
/// The level.
/// The message.
/// The parameters.
public abstract void Progress(int level, string message, params object[] parameters);
///
/// Logs the specified warning.
///
/// The message.
public void Warning(string code, string message)
{
Warning(code, "{0}", message);
}
///
/// Logs the specified warning.
///
public void Warning(string code, string message, params object[] parameters)
{
LogRawMessage(LogLevel.Warning, code, message, null, parameters);
}
///
/// Logs the specified error.
///
public void Error(string code, string message, Exception ex, params object[] parameters)
{
LogRawMessage(LogLevel.Error, code, message, ex, parameters);
}
///
/// Logs the specified error.
///
public void Error(string code, string message)
{
Error(code, "{0}", message);
}
///
/// Logs the specified error.
///
public void Error(string code, string message, params object[] parameters)
{
Error(code, message, null, parameters);
}
///
/// Logs the specified fatal error.
///
public void Fatal(string message, Exception ex, params object[] parameters)
{
LogRawMessage(LogLevel.Fatal, null, message, ex, parameters);
Exit("A fatal error occured");
}
///
/// Logs the specified fatal error.
///
public void Fatal(string message)
{
Fatal("{0}", message);
}
///
/// Logs the specified fatal error.
///
public void Fatal(string message, params object[] parameters)
{
Fatal(message, null, parameters);
}
///
/// Exits the process.
///
public abstract void Exit(string reason, params object[] parameters);
///
/// Logs the raw message to the LoggerOutput.
///
public abstract void LogRawMessage(LogLevel type, string code, string message, Exception exception, params object[] parameters);
}
}