Skip to content

Cannot set connection string for Azure Data Tables using ${var:connectionString} #135

@akakira

Description

@akakira

Recently I've been converting out sql server logging using nlog to azure data tables, using your AzureStorage extension. Everything works great when I set the connection string via text in the nlog config file, or via the appsettings. However due to security restrictions I must load the connection string from a keyvault on startup. I have modified my nlog.config like so:

<?xml version="1.0" encoding="utf-8" ?>
<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" internalLogLevel="Trace" internalLogToConsole="true">
  <extensions>
    <add assembly="NLog.Extensions.AzureDataTables" /> 
  </extensions>
  <targets>
    <target xsi:type="AzureDataTables"
            connectionString="${var:storageConnectionString}"
            name="AzureTable"
            tableName="ErrorLogs">
      <contextproperty name="CallSite" layout="${callsite:filename=true}" />
      <contextproperty name="Date" layout="${longdate}" />
      <contextproperty name="Exception" layout="${exception}" />
      <contextproperty name="Level" layout="${level}" />
      <contextproperty name="Logger" layout="${logger}" />
      <contextproperty name="MachineName" layout="${machinename}" />
      <contextproperty name="Message" layout="${message}" />
      <contextproperty name="StackTrace" layout="${stacktrace}" />
      <contextproperty name="Thread" layout="${threadid}" />
    </target>
  </targets>
  <rules>
    <logger name="*" writeTo="AzureTable"  />
  </rules>
</nlog>

and set that during my Startup.cs using the following:
LogManager.Configuration.Variables["storageConnectionString"] = Settings.StorageConnectionString;

The connection string never gets set using that method. Is there a workaround for this?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions