Log4net Json定制属性未读取 [英] Log4net Json custom properties not being read

查看:102
本文介绍了Log4net Json定制属性未读取的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用log4net在sql数据库中插入JSON格式的数据.除了未保存的自定义属性,其他一切都很好.

I am inserting JSON format data in sql database using log4net. Everything is fine except custom properties which are not being saved.

这是我的配置:

<appender name="TGGADONetAppenderjson" type="log4net.Appender.ADONetAppender">
      <bufferSize value="1" />
      <connectionType value="System.Data.SqlClient.SqlConnection, System.Data,       Version=1.0.3300.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
      <connectionString value="Data Source=LOANER-1122-HP\SQLEXPRESS;Initial Catalog=CAS-Dev;integrated security=false;persist security info=True;User Id=sa;Password=abinash12345;" />
      <commandText value="INSERT INTO Log ([Message],[AppName],[TransactionId]) VALUES
       (@message, @appName,@transactionId)" />

 <parameter>
        <parameterName value="@message" />
        <dbType value="String" />
        <size value="4000" />
        <layout type="log4net.Layout.SerializedLayout, log4net.Ext.Json"></layout>
      </parameter>
<parameter>
        <parameterName value="@appName" />
        <dbType value="String" />
        <size value="2000" />
        <layout type="log4net.Layout.PatternLayout">
          <!--<conversionPattern value="%property{Environment}" />-->
          <conversionPattern value="APPNAME-LogTest" />
          <!--should be a fixed value-->
        </layout>
      </parameter>
      <parameter>
        <parameterName value="@transactionId" />
        <dbType value="String" />
        <size value="2000" />
        <layout type="log4net.Layout.PatternLayout" >
          <conversionPattern value="%property{TransactionId}" />
        </layout>
      </parameter>
    </appender>

    <root>
      <level value="ALL" />
      <appender-ref ref="TGGADONetAppenderjson" />
    </root>

当我调试时,我可以看到自定义属性"TransactionId"的值被放入线程中.但是,插入无法正常工作.未在消息中记录TransactionId,也未将其插入TransactionId列中.

When I debug, I can see the values of the custom property "TransactionId" is being put into the thread. However the insert does not work. The TransactionId is not logged in the message nor inserted into the column TransactionId.

我正在使用NuGet的log4net json版本1.2.13.29

I am using log4net json version 1.2.13.29 from NuGet

推荐答案

在SerializedLayout中还有更多配置.您需要显式命名属性.尝试类似的东西:

There's some more configuration to go into the SerializedLayout. You need to explicitly name the property. Try something like:

<layout type='log4net.Layout.SerializedLayout, log4net.Ext.Json'>
    <decorator type='log4net.Layout.Decorators.StandardTypesDecorator, log4net.Ext.Json' />
    <default /> <!-- explicit default members -->
    <member value='TransactionId' /> <!-- explicit property reference -->
</layout> 

检查

Check the Members test case that might help you.

或者,通过添加properties成员来序列化所有属性.

Alternatively, serialize all the properties by adding a properties member.

这篇关于Log4net Json定制属性未读取的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆