log4net.RabbitMQ Appender

3.2k views Asked by At

I'm trying to use the log4net RabbitMQAppender in a C# web application. I couldn't build and run the samples under https://github.com/haf/log4net.RabbitMQ. In the log4net.config file I couldn't figure out how do I need to set the connection parameters to RabbitMQ (host, port, ssl settings, etc.)

    <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>

Does anybody have any experience with that library. A simple web app sample would be of great help.

1

There are 1 answers

2
dmarlow On BEST ANSWER

Looking at the documentation on the page https://github.com/haf/log4net.RabbitMQ

It seems that you put the connection information under the appender properties for example

<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>