Skip to content

Latest commit

 

History

History
149 lines (98 loc) · 5.93 KB

File metadata and controls

149 lines (98 loc) · 5.93 KB

Azure ServiceBus

Package Name NuGet Description
NLog.Extensions.AzureServiceBus NuGet Azure Service Bus

ServiceBus Configuration

Syntax

<extensions>
  <add assembly="NLog.Extensions.AzureServiceBus" /> 
</extensions>

<targets>
  <target xsi:type="AzureServiceBus"
          name="String"
          layout="Layout"
          connectionString="Layout"
          queueName="Layout"
          topicName="Layout"
          sessionId="Layout"
          partitionKey="Layout"
          subject="Layout"
          contentType="Layout"
          messageId="Layout"
          correlationId="Layout">
	    <messageProperty name="level" layout="${level}" />
	    <messageProperty name="exception" layout="${exception:format=shorttype}" includeEmptyValue="false" />
	    <layout type="JsonLayout" includeAllProperties="true">
		    <attribute name="time" layout="${longdate}" />
		    <attribute name="message" layout="${message}" />
		    <attribute name="threadid" layout="${threadid}" />
		    <attribute name="exception" layout="${exception:format=tostring}" />
	    </layout>
  </target>
</targets>

Parameters

name - Name of the target.

connectionString - Azure storage connection string. Layout Required.

queueName - QueueName for multiple producers single consumer. Layout

topicName - TopicName for multiple producers and multiple subscribers. Layout

sessionId - SessionId-Key which Service Bus uses to generate PartitionId-hash. Layout

partitionKey - Partition-Key which Service Bus uses to generate PartitionId-hash. Layout

subject - Service Bus Message Subject to be used as label for the message. Layout

layout - Service Bus Message Body to be rendered and encoded as UTF8. Layout Required.

contentType - Service Bus Message Body ContentType. Layout. Ex. application/json

messageId - Service Bus Message MessageId. Layout

correlationId - Service Bus Message Correlationid. Layout

timeToLiveSeconds - Default Time-To-Live (TTL) for ServiceBus messages in seconds (Optional)

timeToLiveDays - Default Time-To-Live (TTL) for ServiceBus messages in days (Optional)

useWebSockets - Enable AmqpWebSockets. Ex. true/false (optional)

webSocketProxyAddress - Custom WebProxy address for WebSockets (optional)

customEndpointAddress - Custom endpoint address that can be used when establishing the connection (optional)

serviceUri - Alternative to ConnectionString, where Managed Identiy is applied from DefaultAzureCredential for User delegation SAS.

tenantIdentity - Alternative to ConnectionString. Used together with ServiceUri. Input for DefaultAzureCredential.

resourceIdentity - Alternative to ConnectionString. Used together with ServiceUri. Input for DefaultAzureCredential as ManagedIdentityResourceId.

clientIdentity - Alternative to ConnectionString. Used together with ServiceUri. Input for DefaultAzureCredential as ManagedIdentityClientId.

sharedAccessSignature - Alternative to ConnectionString. Used together with ServiceUri. Input for AzureSasCredential

accountName - Alternative to ConnectionString. Used together with ServiceUri. Input for AzureNamedKeyCredential-AccountName

accessKey - Alternative to ConnectionString. Used together with ServiceUri. Input for AzureNamedKeyCredential-AccessKey

Batching Policy

maxBatchSizeBytes - Max size of a single batch in bytes Integer (Default=256*1024)

batchSize - Number of LogEvents to send in a single batch (Default=100)

taskDelayMilliseconds - Artificial delay before sending to optimize for batching (Default=200 ms)

queueLimit - Number of pending LogEvents to have in memory queue, that are waiting to be sent (Default=10000)

overflowAction - Action to take when reaching limit of in memory queue (Default=Discard)

Retry Policy

taskTimeoutSeconds - How many seconds a Task is allowed to run before it is cancelled (Default 150 secs)

retryDelayMilliseconds - How many milliseconds to wait before next retry (Default 500ms, and will be doubled on each retry).

retryCount - How many attempts to retry the same Task, before it is aborted (Default 0)

Azure ConnectionString

NLog Layout makes it possible to retrieve settings from many locations.

Lookup ConnectionString from appsettings.json

connectionString="${configsetting:ConnectionStrings.AzureBus}"

  • Example appsettings.json on .NetCore:
  {
    "ConnectionStrings": {
      "AzureBus": "UseDevelopmentStorage=true;"
    }
  }

Lookup ConnectionString from app.config

connectionString="${appsetting:ConnectionStrings.AzureBus}"

  • Example app.config on .NetFramework:
   <configuration>
      <connectionStrings>
        <add name="AzureBus" connectionString="UseDevelopmentStorage=true;"/>
      </connectionStrings>
   </configuration>

Lookup ConnectionString from environment-variable

connectionString="${environment:AZURE_STORAGE_CONNECTION_STRING}"

Lookup ConnectionString from NLog GlobalDiagnosticsContext (GDC)

connectionString="${gdc:AzureBusConnectionString}"

  • Example code for setting GDC-value:
  NLog.GlobalDiagnosticsContext.Set("AzureBusConnectionString", "UseDevelopmentStorage=true;");