using System;
using System.Runtime.CompilerServices;
using ImageProcessor.Common.Exceptions;
using Umbraco.Core.Composing;
using Umbraco.Core.Logging;
namespace Umbraco.Web
{
///
/// A logger for explicitly logging ImageProcessor exceptions.
///
/// Creating this logger is enough for ImageProcessor to find and replace its in-built debug logger
/// without any additional configuration required. This class currently has to be public in order
/// to do so.
///
///
public sealed class ImageProcessorLogger : ImageProcessor.Common.Exceptions.ILogger
{
///
/// Logs the specified message as an error.
///
/// The type calling the logger.
/// The message to log.
/// The property or method name calling the log.
/// The line number where the method is called.
public void Log(string text, [CallerMemberName] string callerName = null, [CallerLineNumber] int lineNumber = 0)
{
// Using LogHelper since the ImageProcessor logger expects a parameterless constructor.
var message = $"{callerName} {lineNumber} : {text}";
Current.Logger.Error(new ImageProcessingException(message));
}
///
/// Logs the specified message as an error.
///
/// The type calling the logger.
/// The message to log.
/// The property or method name calling the log.
/// The line number where the method is called.
public void Log(Type type, string text, [CallerMemberName] string callerName = null, [CallerLineNumber] int lineNumber = 0)
{
// Using LogHelper since the ImageProcessor logger expects a parameterless constructor.
var message = $"{callerName} {lineNumber} : {text}";
Current.Logger.Error(type, new ImageProcessingException(message));
}
}
}