Files
Umbraco-CMS/src/Umbraco.Web/ImageProcessorLogger.cs

49 lines
2.2 KiB
C#
Raw Normal View History

2017-05-12 14:49:44 +02:00
using System;
using System.Runtime.CompilerServices;
using ImageProcessor.Common.Exceptions;
2017-05-30 15:46:25 +02:00
using Umbraco.Core.Composing;
using Umbraco.Core.Logging;
namespace Umbraco.Web
2017-07-20 11:21:28 +02:00
{
/// <summary>
/// A logger for explicitly logging ImageProcessor exceptions.
/// <remarks>
/// Creating this logger is enough for ImageProcessor to find and replace its in-built debug logger
2017-07-20 11:21:28 +02:00
/// without any additional configuration required. This class currently has to be public in order
/// to do so.
/// </remarks>
/// </summary>
public sealed class ImageProcessorLogger : ImageProcessor.Common.Exceptions.ILogger
{
/// <summary>
/// Logs the specified message as an error.
/// </summary>
/// <typeparam name="T">The type calling the logger.</typeparam>
/// <param name="text">The message to log.</param>
/// <param name="callerName">The property or method name calling the log.</param>
/// <param name="lineNumber">The line number where the method is called.</param>
public void Log<T>(string text, [CallerMemberName] string callerName = null, [CallerLineNumber] int lineNumber = 0)
{
// Using LogHelper since the ImageProcessor logger expects a parameterless constructor.
2016-07-08 17:58:01 +02:00
var message = $"{callerName} {lineNumber} : {text}";
Current.Logger.Error<T>(new ImageProcessingException(message));
}
/// <summary>
/// Logs the specified message as an error.
/// </summary>
/// <param name="type">The type calling the logger.</param>
/// <param name="text">The message to log.</param>
/// <param name="callerName">The property or method name calling the log.</param>
/// <param name="lineNumber">The line number where the method is called.</param>
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.
2016-07-08 17:58:01 +02:00
var message = $"{callerName} {lineNumber} : {text}";
Current.Logger.Error(type, new ImageProcessingException(message));
}
}
}