public EmailTemplateModel(LoggingEvent loggingEvent)
        {
            if (loggingEvent == null)
                throw new ArgumentNullException("loggingEvent");

            LoggingEvent = loggingEvent;
            HttpContextInformation = loggingEvent.GetData<HttpContextInformation>(Constants.DataKeys.HttpContext);
            StackTrace = loggingEvent.GetData<string>(Constants.DataKeys.StackTrace);
            SqlInformation = loggingEvent.GetData<SqlInformation>(Constants.DataKeys.SQL);
            ExceptionInformation = loggingEvent.GetData<ExceptionInformation>(Constants.DataKeys.Exception);

            GeneralSection = new Dictionary<string, object>();
            LoadGeneralSection();

            CustomData = loggingEvent.Data.Where(x => !x.Key.StartsWith("MS_", StringComparison.InvariantCultureIgnoreCase)).ToDictionary(x => x.Key, x => x.Value);
            if (!CustomData.Any())
                CustomData = null;

            RequestSection = new Dictionary<string, object>();
            LoadRequestSection();

            LevelText = Enum.GetName(typeof (LoggingEventLevel), LoggingEvent.Level);
            LevelClass = "green";
            var loggingEventLevelValue = (int) loggingEvent.Level;
            if (loggingEventLevelValue >= 40000 && loggingEventLevelValue <= 60000)
                LevelClass = "yellow";
            else if (loggingEventLevelValue > 60000)
                LevelClass = "red";

            Footer = string.Format(CultureInfo.InvariantCulture, "Pulsus | {0} | {1}", Constants.Version, Constants.WebSite);
        }
        public void NullDataValueShouldReturnDefaultValue()
        {
            var loggingEvent = new LoggingEvent();
            loggingEvent.Data.Add("test", null);

            var value = loggingEvent.GetData<string>("test");

            value.Should().Be.Null();
        }
        public void SerializedDataShoudBeCorrectlyDeserialized()
        {
            const string serializedData = "{ \"custom-data\" : { \"StringField\" : \"test\", \"IntField\" : 9 } }";
            var loggingEvent = new LoggingEvent();
            loggingEvent.Data = JsonConvert.DeserializeObject<IDictionary<string, object>>(serializedData);

            var result = loggingEvent.GetData<CustomData>("custom-data");
            result.Should().Not.Be.Null();
            result.StringField.Should().Be("test");
            result.IntField.Should().Be(9);
        }
        public void NonSerializedDataShouldCorrectlyRetrieved()
        {
            var loggingEvent = new LoggingEvent();
            loggingEvent.Data["custom-data"] = new CustomData()
            {
                StringField = "test",
                IntField = 9
            };

            var result = loggingEvent.GetData<CustomData>("custom-data");
            result.Should().Not.Be.Null();
            result.StringField.Should().Be("test");
            result.IntField.Should().Be(9);
        }
        public static DatabaseLoggingEvent Serialize(LoggingEvent loggingEvent)
        {
            var result = new DatabaseLoggingEvent();
            result.EventId = Truncate(loggingEvent.EventId, 38);
            result.LogKey = Truncate(loggingEvent.LogKey, 100);
            result.ApiKey = Truncate(loggingEvent.ApiKey, 100);
            result.Date = loggingEvent.Date;
            result.Level = (int)loggingEvent.Level;
            result.Value = loggingEvent.Value;
            result.Text = Truncate(loggingEvent.Text, 5000);
            result.Tags = Truncate(string.Join(" ", loggingEvent.Tags.ToArray()), 1000);
            result.Data = LogManager.JsonSerializer.SerializeObject(loggingEvent.Data);

            result.MachineName = Truncate(loggingEvent.MachineName, 100);
            result.CorrelationId = Truncate(loggingEvent.CorrelationId, 50);
            result.User = Truncate(loggingEvent.User, 500);
            result.Psid = Truncate(loggingEvent.Psid, 50);
            result.Ppid = Truncate(loggingEvent.Ppid, 50);

            var httpContextInfo = loggingEvent.GetData<HttpContextInformation>(Constants.DataKeys.HttpContext);
            if (httpContextInfo != null)
            {
                result.Host = Truncate(httpContextInfo.Host, 255);
                result.Url = Truncate(httpContextInfo.Url, 2000);
                result.HttpMethod = Truncate(httpContextInfo.Method, 10);
                result.IpAddress = Truncate(httpContextInfo.IpAddress, 40);

                if (result.CorrelationId == null)
                    result.CorrelationId = Truncate(httpContextInfo.CorrelationId, 50);
                if (result.User == null)
                    result.User = Truncate(httpContextInfo.User, 500);
                if (result.Psid == null)
                    result.Psid = Truncate(httpContextInfo.Psid, 50);
                if (result.Ppid == null)
                    result.Ppid = Truncate(httpContextInfo.Ppid, 50);
            }

            var exceptionInfo = loggingEvent.GetData<ExceptionInformation>(Constants.DataKeys.Exception);
            if (exceptionInfo != null)
            {
                result.StatusCode = exceptionInfo.StatusCode;
                result.Source = Truncate(exceptionInfo.Source, 500);
            }

            result.Count = loggingEvent.Count;
            result.Hash = loggingEvent.Hash;

            return result;
        }