Package Name | NuGet | Description |
---|---|---|
NLog.Extensions.AzureBlobStorage | Azure Blob Storage |
<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>
name - Name of the target.
layout - Text to be rendered. Layout Required.
blobName - BlobName. Layout
container - Azure blob container name. Layout
contentType - Azure blob ContentType (Default = text/plain)
connectionString - Azure storage connection string. Ex. UseDevelopmentStorage=true;
serviceUri - Alternative to ConnectionString, where Managed Identiy is acquired 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 StorageSharedKeyCredential-AccountName
accessKey - Alternative to ConnectionString. Used together with ServiceUri. Input for StorageSharedKeyCredential-AccessKey
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)
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)
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
NLog Layout makes it possible to retrieve settings from many locations.
connectionString="${configsetting:ConnectionStrings.AzureBlob}"
- Example appsettings.json on .NetCore:
{
"ConnectionStrings": {
"AzureBlob": "UseDevelopmentStorage=true;"
}
}
connectionString="${appsetting:ConnectionStrings.AzureBlob}"
- Example app.config on .NetFramework:
<configuration>
<connectionStrings>
<add name="AzureBlob" connectionString="UseDevelopmentStorage=true;"/>
</connectionStrings>
</configuration>
connectionString="${environment:AZURE_STORAGE_CONNECTION_STRING}"
connectionString="${gdc:AzureBlobConnectionString}"
- Example code for setting GDC-value:
NLog.GlobalDiagnosticsContext.Set("AzureBlobConnectionString", "UseDevelopmentStorage=true;");