- 2 minutes to read

1. Code

var connectionString = "{Your ServiceBus Connection String";
var queueName = "{Your ServiceBus Queue Name}";

var settings = new NodiniteLogEventSettings()
{
    LogAgentValueId = 42,
    EndPointDirection = 0,
    EndPointTypeId = 0,
    EndPointUri = "Nodinite.Serilog.ServiceBusSink.Tests.Serilog",
    EndPointName = "Nodinite.Serilog.ServiceBusSink.Tests",
    ProcessingUser = "NODINITE",
    ProcessName = "Nodinite.Serilog.ServiceBusSink.Tests",
    ProcessingMachineName = "NODINITE-DEV",
    ProcessingModuleName = "DOTNETCORE.TESTS",
    ProcessingModuleType = "DOTNETCORE.TESTPROJECT"
};

ILogger log = new LoggerConfiguration()
    .WriteTo.NodiniteServiceBusSink(connectionString, queueName, settings)
    .CreateLogger();

2. Appsettings.json

{
  "Serilog": {
    "Using": [ "Nodinite.Serilog.ServiceBusSink" ],
    "WriteTo": [
      {
        "Name": "NodiniteServiceBusSink",
        "Args": {
          "ConnectionString": "",
          "QueueName": "",
          "Settings": {
            "LogAgentValueId": 42,
            "EndPointName": "Nodinite.Serilog.ServiceBusSink.Tests",
            "EndPointUri": "Nodinite.Serilog.ServiceBusSink.Tests.Serilog",
            "EndPointDirection": 0,
            "EndPointTypeId": 86,
            "OriginalMessageTypeName": "https://ACME.com/Customers/1.0#Batch",
            "ProcessingUser": "NODINITE",
            "ProcessName": "Nodinite.Serilog.ServiceBusSink.Tests",
            "ProcessingMachineName": "NODINITE-DEV",
            "ProcessingModuleName": "DOTNETCORE.TESTS",
            "ProcessingModuleType": "DOTNETCORE.TESTPROJECT"
          }
        }
      }
    ]
  }
}
var configuration = new ConfigurationBuilder()
    // NOTE: If required, make sure to set the base path, for example: 
    // .SetBasePath(Directory.GetCurrrentDirectory())
    .AddJsonFile("appsettings.json")
    .Build();

Logger log = new LoggerConfiguration()
    .ReadFrom.Configuration(configuration)
    .CreateLogger();