Skip to content

Latest commit

 

History

History
143 lines (96 loc) · 5.44 KB

File metadata and controls

143 lines (96 loc) · 5.44 KB

Azure Table Storage and Cosmos Table

Package Name NuGet Description
NLog.Extensions.AzureDataTables NuGet Azure Table Storage or Azure CosmosDb Tables

Table Configuration

Supports both Azure Storage Tables and CosmosDB Tables.

Syntax

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

<targets>
  <target xsi:type="AzureDataTables"
          name="String"
          layout="Layout"
          connectionString="String"
          tableName="Layout"
          logTimeStampFormat="O" />
</targets>

Parameters

name - Name of the target.

layout - Text to be rendered. Layout Required.

connectionString - Azure storage connection string. Layout

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 TableSharedKeyCredential storage account-name.

accessKey - Alternative to ConnectionString. Used together with ServiceUri. Input for TableSharedKeyCredential account-access-key.

tableName - Azure table name. Layout

rowKey - Azure Table RowKey. Layout. Default = "InverseTicks_${guid}"

partitionKey - Azure PartitionKey. Layout. Default = ${logger}

logTimeStampFormat - Default Log TimeStamp is set to 'O' for Round-trip format if not specified.

Dynamic TableEntity

Instead of using the predefined NLogEntity-properties, then one can specify wanted properties:

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

<targets>
  <target xsi:type="AzureDataTables"
          name="String"
          connectionString="Layout"
          tableName="Layout">
    <contextproperty name="Level" layout="${level}" />
    <contextproperty name="LoggerName" layout="${logger}" />
    <contextproperty name="Message" layout="${message:raw=true}" />
    <contextproperty name="Exception" layout="${exception:format=tostring}" />
    <contextproperty name="FullMessage" layout="${message}" />
    <contextproperty name="MachineName" layout="${machinename}" />
  </target>
</targets>

It will by default include the hardcoded property LogTimeStamp of type DateTime that contains LogEventInfo.TimeStamp.ToUniversalTime().

  • This can be overriden by having <contextproperty name="LogTimeStamp"> as the first property, where empty property-value means leave out.

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 ConnectionString

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

Lookup ConnectionString from appsettings.json

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

  • Example appsettings.json on .NetCore:
  {
    "ConnectionStrings": {
      "AzureTable": "Server=tcp:server.database.windows.net;"
    }
  }

Lookup ConnectionString from app.config

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

  • Example app.config on .NetFramework:
  <configuration>
    <connectionStrings>
      <add name="AzureTable" connectionString="Server=tcp:server.database.windows.net;"/>
    </connectionStrings>
  </configuration>

Lookup ConnectionString from environment-variable

connectionString="${environment:AZURESQLCONNSTR_CONNECTION_STRING}"

Lookup ConnectionString from NLog GlobalDiagnosticsContext (GDC)

connectionString="${gdc:AzureTableConnectionString}"

  • Example code for setting GDC-value:
  NLog.GlobalDiagnosticsContext.Set("AzureTableConnectionString", "Server=tcp:server.database.windows.net;");