Skip to content

Latest commit

 

History

History
151 lines (95 loc) · 5.99 KB

File metadata and controls

151 lines (95 loc) · 5.99 KB

Azure BlobStorage

Package Name NuGet Description
NLog.Extensions.AzureBlobStorage NuGet Azure Blob Storage

Blob Configuration

Syntax

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

<targets>
  <target xsi:type="AzureBlobStorage"
          name="String"
          layout="Layout"
          connectionString="Layout"
          blobName="Layout"
          container="Layout">
            <metadata name="mymeta" layout="mymetavalue" />   <!-- Multiple allowed -->
            <tag name="mytag" layout="mytagvalue" /> <!-- Multiple allowed (Requires v2 storage accounts) -->
  </target>
</targets>

General Options

name - Name of the target.

layout - Text to be rendered. Layout Required.

blobName - BlobName. Layout Required.

container - Azure blob container name. Layout Required.

contentType - Azure blob ContentType (Default = text/plain)

connectionString - Azure Blob Storage connection string from your storage account. Required unless using ServiceUri.

serviceUri - Uri to reference the blob service (e.g. https://{account_name}.blob.core.windows.net). Alternative to ConnectionString, where Managed Identiy is applied from DefaultAzureCredential.

Authentication Options

managedIdentityClientId - clientId for ManagedIdentityClientId on DefaultAzureCredentialOptions. Requires serviceUri.

managedIdentityResourceId - resourceId for ManagedIdentityResourceId on DefaultAzureCredentialOptions, do not use together with ManagedIdentityClientId. Requires serviceUri.

tenantIdentity - tenantId for DefaultAzureCredentialOptions and ClientSecretCredential. Requires serviceUri.

sharedAccessSignature - Access signature for AzureSasCredential authentication. Requires serviceUri.

accountName - accountName for StorageSharedKeyCredential authentication. Requires serviceUri and accessKey.

accessKey - accountKey for StorageSharedKeyCredential authentication. Requires serviceUri and accountName.

clientAuthId - clientId for ClientSecretCredential OAuth2 authentication. Requires serviceUri, tenantIdentity and clientAuthSecret.

clientAuthSecret - clientSecret for ClientSecretCredential OAuth2 authentication. Requires serviceUri,tenantIdentity and clientAuthId.

When using ServiceUri (Instead of ConnectionString) with DefaultAzureCredential, then Azure Identity can also resolve from environment variables:

  • AZURE_CLIENT_ID - For ManagedIdentityClientId / WorkloadIdentityClientId
  • AZURE_TENANT_ID - For TenantId

See also: Set up Your Environment for Authentication

Proxy Options

noProxy - Bypasses any system proxy and proxy in ProxyAddress when set to true.

proxyAddress - Address of the proxy server to use (e.g. http://proxyserver:8080).

proxyLogin - Login to use for the proxy server. Requires proxyPassword.

proxyPassword - Password to use for the proxy server. Requires proxyLogin.

useDefaultCredentialsForProxy - Uses the default credentials (System.Net.CredentialCache.DefaultCredentials) for the proxy server. Take precedence over proxyLogin and proxyPassword when set to true.

Batching Policy

batchSize - Number of EventData items 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 Blob Storage Emulator

The AzureBlobStorage-target uses Append blob operations, which is not support by Azure Storage Emulator from Microsoft.

It will fail with the following error:

Azure.RequestFailedException: This feature is not currently supported by the Storage Emulator

Instead one can try an alternative Azure Storage Emulator like Azurite

Azure ConnectionString

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

Lookup ConnectionString from appsettings.json

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

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

Lookup ConnectionString from app.config

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

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

Lookup ConnectionString from environment-variable

connectionString="${environment:AZURE_STORAGE_CONNECTION_STRING}"

Lookup ConnectionString from NLog GlobalDiagnosticsContext (GDC)

connectionString="${gdc:AzureBlobConnectionString}"

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