سؤال

I am adding properties into

LogicalThreadContext.Properties["callContextId"] = "123456";

And my config looks like this:

<parameter>
  <parameterName value="@CallContextId" />
  <dbType value="String" />
  <layout type="log4net.Layout.PatternLayout">
    <conversionPattern value="%property{callContextId}" />
  </layout>
</parameter>

This all works... but can I add a complex object and access its property? e.g.

myObject.Id = "123456";
LogicalThreadContext.Properties["callContext"] = myObject;

and I want to do something like this... is it at all supported/possible?

<conversionPattern value="%property{callContext}.Id" />

Thanks

هل كانت مفيدة؟

المحلول

No, it isn't supported by log4net.

If you look at the code in PropertyPatternConverter, you see it calls WriteObject in the PatternConverter class, which then just calls ToString on the object stored in the property.

It wouldn't be easy to implement either, as you would have to have code to extract the property name, then use reflection to extract the value. As you can accomplish the same thing by just storing the object property's value in the LogicalThreadContext.Properties, it isn't worthwhile.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top