/* web/app.config
*/
/* Log4net_normal.xml
*/
using System.Configuration;
using System.Diagnostics;
using System.Linq;
using Ashley.Distribution.Wms.Bootstrap;
using Ashley.Distribution.Wms.Contracts.IntegrationServices;
using Ashley.Integration.SDK;
using log4net.Appender;
using log4net.Core;
namespace Ashley.Distribution.Wms.Common
{
public class NotificationAppender : BufferingAppenderSkeleton
{
protected override void SendBuffer(LoggingEvent[] loggingEvents)
{
var sendNotifications = ConfigurationManager.AppSettings.AllKeys.Contains("SendNotifications") && ConfigurationManager.AppSettings["SendNotifications"] == "True";
var integrationContext = IoCContainer.Resolve();
if (sendNotifications && integrationContext != null)
{
foreach (var loggingEvent in loggingEvents)
{
if (loggingEvent.Level.Value >= Level.Error.Value)
{
var toEmailAddress = ConfigurationManager.AppSettings["NotificationToList"];
var fromEmailAddress = ConfigurationManager.AppSettings["NotificationFrom"];
var contentType = ConfigurationManager.AppSettings["NotificationContentType"];
var subjectTemplate = ConfigurationManager.AppSettings["NotificationSubject"];
var message = loggingEvent.MessageObject.ToString();
integrationContext.PublishEnterpriseNotificationEvent(toEmailAddress, fromEmailAddress, contentType, subjectTemplate, message);
integrationContext.PublishEnterpriseTraceEvent(eTraceInfoType.ERROR, message);
integrationContext.PublishLocalApplicationEventLogEvent(message, EventLogEntryType.Error);
}
if (loggingEvent.Level == Level.Warn)
{
var message = loggingEvent.MessageObject.ToString();
integrationContext.PublishEnterpriseTraceEvent(eTraceInfoType.WARNING, message);
integrationContext.PublishLocalApplicationEventLogEvent(message, EventLogEntryType.Warning);
}
if (loggingEvent.Level == Level.Debug || loggingEvent.Level == Level.Info)
{
var message = loggingEvent.MessageObject.ToString();
integrationContext.PublishEnterpriseTraceEvent(eTraceInfoType.INFO, message);
integrationContext.PublishLocalApplicationEventLogEvent(message, EventLogEntryType.Information);
}
}
}
}
}
}