本文整理汇总了C#中Logger.SetContext方法的典型用法代码示例。如果您正苦于以下问题:C# Logger.SetContext方法的具体用法?C# Logger.SetContext怎么用?C# Logger.SetContext使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Logger
的用法示例。
在下文中一共展示了Logger.SetContext方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TestSetContextWithNullLogContextProperties
public void TestSetContextWithNullLogContextProperties()
{
var logContext = new LogContext(null);
var logger = new Logger();
logger.SetContext(logContext);
Assert.Equal(0, logger.Properties.Count);
}
示例2: TestSetContextDoesNotSetNonPropertyKeysProperty
public void TestSetContextDoesNotSetNonPropertyKeysProperty()
{
var logContext = new LogContext();
var logger = new Logger();
logContext.Properties["k1"] = "v1";
logger.SetContext(logContext);
Assert.Equal(0, logger.Properties.Count);
Assert.Equal(null, logger.GetProperty("k1"));
}
示例3: TestClearContextClearsOnlyPropertyKeysProperties
public void TestClearContextClearsOnlyPropertyKeysProperties()
{
var logContext = new LogContext();
var logger = new Logger();
foreach (var propertyKeyField in LogContext.PropertyKey.Fields)
{
var propertyKey = propertyKeyField.GetValue(logContext) as string;
logContext.Properties[propertyKey] = propertyKey;
}
logger.SetContext(logContext);
logger.SetProperty("k1", "v1");
logger.ClearContext();
Assert.Equal(1, logger.Properties.Count);
Assert.Equal("v1", logger.GetProperty("k1"));
}
示例4: TestSetContextSetsOnlyPropertyKeys
public void TestSetContextSetsOnlyPropertyKeys()
{
var logContext = new LogContext();
var logger = new Logger();
foreach (var propertyKeyField in LogContext.PropertyKey.Fields)
{
var propertyKey = propertyKeyField.GetValue(logContext) as string;
logContext.Properties[propertyKey] = propertyKey;
}
logger.SetContext(logContext);
Assert.Equal(logContext.Properties.Count, logger.Properties.Count);
foreach (var propertyKeyField in LogContext.PropertyKey.Fields)
{
var propertyKey = propertyKeyField.GetValue(logContext) as string;
var propertyValue = logger.GetProperty(propertyKey);
Assert.Equal(logContext.Properties[propertyValue], propertyValue);
}
}