ArieGato / serilog-sinks-rabbitmq

Serilog Sink for RabbitMq
Apache License 2.0
56 stars 53 forks source link

How to setup an audit logger and a standard logger through Json config #203

Closed Pastafarian closed 7 months ago

Pastafarian commented 7 months ago

Hello,

I am a bit stuck, I want to setup both an audit logger and a standard logger using Json config.

The example given works well for creating a single logger, but I don't know how to extend it so I can configure both a standard and an audit logger. Is there a way of loading in two "WriteTo" configurations?

If not, my first thought would be to extend the configuration so we have seperate settings for both types of logger. Example below.

{
  "Serilog": {
    "Using":  ["Serilog.Sinks.RabbitMQ"],
    "MinimumLevel": "Debug",
    "WriteTo": [
      {
        "Name": "RabbitMQ", 
        "Args": { 
          "username": "usr",
          "password": "pwd",
          "hostnames": [
            "localhost"
          ],
          "port": 5672,
          "loggingExchange": "LogExchange",
          "loggingRouteKey": "A",
          "loggingExchangeType": "fanout",
          "loggingDeliveryMode": "durable"
          "auditExchange": "AuditExchange",
          "auditRouteKey": "B",
          "auditExchangeType": "fanout",
          "auditDeliveryMode": "durable"
          "autoCreateExchange": true,
          "batchPostingLimit": 1000,
          "period": 30
        } 
      }
    ]
  }
}

Happy to take a look at implementing, I know this would be a breaking change (unless we aliased the old values to the logging exchange by default, though even then though...). Hoping I just missed something obvious!

ArieGato commented 7 months ago

@Pastafarian I'm not sure, but I think you can use "AuditTo" the same way as "WriteTo"

maybe something like this

{
  "Serilog": {
    "Using":  ["Serilog.Sinks.RabbitMQ"],
    "MinimumLevel": "Debug",
    "WriteTo": [
      {
        "Name": "RabbitMQ", 
        "Args": {
// all args
        } 
      }
    ],
    "AuditTo": [
      {
        "Name": "RabbitMQ", 
        "Args": {
// all args
        } 
      }
    ]
  }
}
ArieGato commented 7 months ago

@Pastafarian I included the AuditTo configuration to the examples.

Pastafarian commented 7 months ago

@ArieGato thanks so much for coming back with a detailed write-up in the docs. Much appreciated, my appologies for not getting back to you sooner.

Please feel free to close this issue.

ArieGato commented 7 months ago

@Pastafarian you're welcome. Glad to help