/ThinkEmailFomatter/Utilities/Extensions/LogExt.cs
C# | 90 lines | 75 code | 9 blank | 6 comment | 5 complexity | 0612d76cb602c65600ed89016e423e68 MD5 | raw file
Possible License(s): BSD-3-Clause
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Web;
- using System.IO;
- using System.Xml;
- using System.Xml.Linq;
- using ThinkEmailFormatter.Models;
- using System.Web.Mvc;
- using Microsoft.Practices.EnterpriseLibrary.Logging;
- using System.Diagnostics;
- using System.Text;
- namespace ThinkEmailFormatter.Models.Extensions
- {
- public static class LogExt
- {
- public static void Warning(this LogWriter log, string message)
- {
- if (log.IsLoggingEnabled())
- {
- LogEntry logEntry = new LogEntry()
- {
- Message = message,
- Severity = TraceEventType.Warning
- };
- log.Write(logEntry);
- }
- }
- public static void Error(this LogWriter log, string message)
- {
- if (log.IsLoggingEnabled())
- {
- LogEntry logEntry = new LogEntry()
- {
- Message = message,
- Severity = TraceEventType.Error
- };
- log.Write(logEntry);
- }
- }
- /// <summary>
- ///
- /// </summary>
- /// <param name="log"></param>
- /// <param name="ie"></param>
- /// <param name="location">Optional parameter that should provide where the exception was thrown(e.g. class.method)</param>
- public static void Exception(this LogWriter log, Exception ie, string location = null)
- {
- if (log.IsLoggingEnabled())
- {
- StringBuilder fullMessage = new StringBuilder(Environment.NewLine);
- if (string.IsNullOrEmpty(location))
- fullMessage.AppendFormat(" An exception was thrown: {0}", ie.Message);
- else
- {
- fullMessage.AppendFormat(" An exception was thrown in {0}.", location);
- fullMessage.Append(Environment.NewLine);
- fullMessage.AppendFormat(" Details: {0}", ie.Message);
- }
- LogEntry logEntry = new LogEntry()
- {
- Message = fullMessage.ToString(),
- Severity = TraceEventType.Error
- };
- log.Write(logEntry);
- }
- }
- public static void Information(this LogWriter log, string message)
- {
- if (log.IsLoggingEnabled())
- {
- LogEntry logEntry = new LogEntry()
- {
- Message = message,
- Severity = TraceEventType.Information
- };
- log.Write(logEntry);
- }
- }
- }
- }