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


C# LogEventInfo.ToBsonDocument方法代码示例

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


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

示例1: BuildBsonDocument

        private BsonDocument BuildBsonDocument(LogEventInfo logEvent)
        {
            var doc = Fields.Count == 0 || AppendFields
                ? logEvent.ToBsonDocument()
                : new BsonDocument();

            if (UseCappedCollection && CreateIdField)
                doc.AddField("_id", ObjectId.GenerateNewId());

            foreach (var field in Fields)
            {
                if (field.Layout != null)
                {
                    var renderedField = field.Layout.Render(logEvent);
                    if (!string.IsNullOrWhiteSpace(renderedField))
                    {
                        var bsonTypeValue = field.BsonType;
                        if (!string.IsNullOrWhiteSpace(bsonTypeValue))
                        {
                            const bool IgnoreCase = true;
                            BsonType bsonType;
                            if (Enum.TryParse(bsonTypeValue, IgnoreCase, out bsonType))
                            {
                                var bsonValue = BsonTypeMapper.MapToBsonValue(renderedField, bsonType);
                                doc[field.Name] = bsonValue;
                            }
                            else
                            {
                                var msg = "Unknown BsonType specified: " + bsonTypeValue;
                                msg += ". Note that the type name must match enum names from the MongoDB.Bson.BsonType in the C# driver and do not necessarily match the MongoDB internal type names.";
                                throw new InvalidOperationException(msg);
                            }
                        }
                        else
                        {
                            doc[field.Name] = renderedField;
                        }
                    }

                    continue;
                }

                var searchResult = logEvent.GetValue(field.Name);
                if (!searchResult.Succeded)
                    throw new InvalidOperationException(string.Format("Invalid field name '{0}'.", field.Name));

                doc.AddField(field.Name, searchResult.Value);
            }

            return doc;
        }
开发者ID:ExactBid,项目名称:NLog.MongoDB,代码行数:51,代码来源:MongoDBTarget.cs

示例2: BuildBsonDocument

        private BsonDocument BuildBsonDocument(LogEventInfo logEvent)
        {
            var doc = Fields.Count == 0 || AppendFields
				? logEvent.ToBsonDocument()
				: new BsonDocument();

			if (UseCappedCollection && CreateIdField)
				doc.AddField("_id", ObjectId.GenerateNewId());

			foreach (var field in Fields)
			{
				if (field.Layout != null)
				{
					var renderedField = field.Layout.Render(logEvent);
					if (!string.IsNullOrWhiteSpace(renderedField))
						doc[field.Name] = renderedField;
					continue;
				}

				var searchResult = logEvent.GetValue(field.Name);
				if (!searchResult.Succeded)
					throw new InvalidOperationException(string.Format("Invalid field name '{0}'.", field.Name));

				doc.AddField(field.Name, searchResult.Value);
			}

			return doc;
		}
开发者ID:pcibraro,项目名称:NLog.MongoDB,代码行数:28,代码来源:MongoDBTarget.cs

示例3: Write

 /// <summary>
 /// Writes logging event to the log target.
 /// classes.
 /// </summary>
 /// <param name="logEvent">Logging event to be written out.</param>
 protected override void Write(LogEventInfo logEvent)
 {
     var document = logEvent.ToBsonDocument(UseFormattedMessage);
     _logRepository.InsertAsync(document).Wait();
 }
开发者ID:dotadam,项目名称:NLog.MongoAsync,代码行数:10,代码来源:MongoTarget.cs


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