log4net.RabbitMQ Appender

时间:2015-06-23 16:53:25

标签: c# .net rabbitmq log4net appender

我试图在C#Web应用程序中使用log4net RabbitMQAppender。我无法在https://github.com/haf/log4net.RabbitMQ下构建和运行样本。 在log4net.config文件中,我无法弄清楚如何将连接参数设置为RabbitMQ(主机,端口,ssl设置等)

    <log4net>
      <appender name="AmqpAppender" type="log4net.RabbitMQ.RabbitMQAppender, log4net.RabbitMQ">
        <topic value="samples.web.{0}" />
        <appId value="Sample Web App for RabbitMQAppender" />
        <layout type="log4net.Layout.PatternLayout">
            <conversionPattern value="%date [%thread] %-5level - %message%newline" />
        </layout>
      </appender>
      <root>
        <level value="DEBUG"/>
        <appender-ref ref="AmqpAppender" />
      </root>
   </log4net>

是否有人对该库有任何经验。一个简单的Web应用程序示例将会有很大的帮助。

1 个答案:

答案 0 :(得分:1)

查看页面https://github.com/haf/log4net.RabbitMQ

上的文档

似乎您将连接信息放在appender属性下 例如

<appender name...>
  <hostName>localhost</hostname>
  <userName>user</hostname>
  <password>$3cret</password>
  <!-- then add the exchange/message properties -->
  <exchangeProperties>
    <name value = "app-logging" />
    <exchangeType value = "topic" />
    <durable value = false />
    <binding>
      <destination value="SomeOtherRabbitMQExchange" />
      <topic value="#" />
    </binding>
  </exchangeProperties>
  <messageProperties>
    <appId value="My Web Application" />
    <topic type="log4net.Layout.PatternLayout">
      <conversionPattern value="samples.web.%level" />
    </topic>
    <contentType type="log4net.Layout.PatternLayout">
      <conversionPattern value="text/plain" />
    </contentType>
    <persistent value = "false" />
    <priority type="log4net.Layout.PatternLayout">
      <conversionPattern value="0" />
    </priority>
    <ExtendedData value="true" />
  </messageProperties>
</appender>