2013-09-02 05:55:45 +03:00
|
|
|
using System;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using System.Linq;
|
|
|
|
using System.Text;
|
|
|
|
using NLog;
|
|
|
|
using NzbDrone.Common.Messaging.Tracking;
|
|
|
|
|
|
|
|
namespace NzbDrone.Common.Instrumentation
|
|
|
|
{
|
|
|
|
public static class LoggerExtensions
|
|
|
|
{
|
2013-09-04 08:01:28 +03:00
|
|
|
public static void Progress(this Logger logger, string message)
|
2013-09-02 05:55:45 +03:00
|
|
|
{
|
2013-09-04 08:01:28 +03:00
|
|
|
LogProgressMessage(logger, message, ProcessState.Running);
|
|
|
|
}
|
2013-09-02 05:55:45 +03:00
|
|
|
|
2013-09-04 08:01:28 +03:00
|
|
|
public static void Progress(this Logger logger, string message, params object[] args)
|
|
|
|
{
|
|
|
|
var formattedMessage = String.Format(message, args);
|
|
|
|
Progress(logger, formattedMessage);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static void Complete(this Logger logger, string message)
|
|
|
|
{
|
|
|
|
LogProgressMessage(logger, message, ProcessState.Completed);
|
2013-09-02 05:55:45 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
public static void Complete(this Logger logger, string message, params object[] args)
|
|
|
|
{
|
|
|
|
var formattedMessage = String.Format(message, args);
|
|
|
|
Complete(logger, formattedMessage);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static void Failed(this Logger logger, string message)
|
|
|
|
{
|
2013-09-04 08:01:28 +03:00
|
|
|
LogProgressMessage(logger, message, ProcessState.Failed);
|
2013-09-02 05:55:45 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
public static void Failed(this Logger logger, string message, params object[] args)
|
|
|
|
{
|
|
|
|
var formattedMessage = String.Format(message, args);
|
|
|
|
Failed(logger, formattedMessage);
|
|
|
|
}
|
2013-09-04 08:01:28 +03:00
|
|
|
|
|
|
|
private static void LogProgressMessage(Logger logger, string message, ProcessState state)
|
|
|
|
{
|
|
|
|
var logEvent = new LogEventInfo(LogLevel.Info, logger.Name, message);
|
|
|
|
logEvent.Properties.Add("Status", state);
|
|
|
|
|
|
|
|
logger.Log(logEvent);
|
|
|
|
}
|
2013-09-02 05:55:45 +03:00
|
|
|
}
|
|
|
|
}
|