当前位置: 首页>>代码示例>>C#>>正文


C# LoggingEvent.GetData方法代码示例

本文整理汇总了C#中LoggingEvent.GetData方法的典型用法代码示例。如果您正苦于以下问题:C# LoggingEvent.GetData方法的具体用法?C# LoggingEvent.GetData怎么用?C# LoggingEvent.GetData使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在LoggingEvent的用法示例。


在下文中一共展示了LoggingEvent.GetData方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: EmailTemplateModel

        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);
        }
开发者ID:eduardocampano,项目名称:pulsus,代码行数:31,代码来源:EmailTemplateModel.cs

示例2: NullDataValueShouldReturnDefaultValue

        public void NullDataValueShouldReturnDefaultValue()
        {
            var loggingEvent = new LoggingEvent();
            loggingEvent.Data.Add("test", null);

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

            value.Should().Be.Null();
        }
开发者ID:eduardocampano,项目名称:pulsus,代码行数:9,代码来源:LoggingEventTests.cs

示例3: SerializedDataShoudBeCorrectlyDeserialized

        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);
        }
开发者ID:eduardocampano,项目名称:pulsus,代码行数:11,代码来源:LoggingEventTests.cs

示例4: NonSerializedDataShouldCorrectlyRetrieved

        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);
        }
开发者ID:eduardocampano,项目名称:pulsus,代码行数:14,代码来源:LoggingEventTests.cs

示例5: Serialize

        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;
        }
开发者ID:eduardocampano,项目名称:pulsus,代码行数:49,代码来源:DatabaseLoggingEvent.cs


注:本文中的LoggingEvent.GetData方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。