本文整理汇总了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;
}
示例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;
}
示例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();
}