title: Audit.NET obtain database credentials dynamically
body: <p>We are using <a href="https://github.com/thepirat000/Audit.NET" rel="nofollow noreferrer">Audit.NET</a> library in our Asp.Net Core project to log user actions. Recently we have decided to use <a href="https://www.vaultproject.io/" rel="nofollow noreferrer">Hashicorp Vault</a> to securely store and obtain secrets including <strong>database credentials</strong>. Vault engine <a href="https://learn.hashicorp.com/tutorials/vault/database-creds-rotation?in=vault/secrets-management" rel="nofollow noreferrer">automatically rotates database credentials</a> on the configured period of time, so static credentials are not an option anymore.</p>
  <p>Thus, we had to implement a service which will serve the current connection string (we are using <strong>PostgreSql</strong>) to the required services. In case of the DB context it is possible to get the connection string at runtime using the following code in <strong>Startup.cs</strong>:</p>
  <pre><code> services.AddDbContext&lt;AppDbContext&gt;((serviceProvider, options) =&gt;
          {
              var databaseCredentialsProvider = serviceProvider.GetRequiredService&lt;IDbConnectionStringProvider&gt;();
              var connectionString = databaseCredentialsProvider.GetConnectionString();
              options.UseNpgsql(connectionString);
          });
  </code></pre>
  <p>However, regarding the Audit.NET configuration, it seems that it can only set static credentials. We are using the following code in <strong>Startup.cs</strong> to configure the Audit.NET.</p>
  <pre><code>Audit.Core.Configuration.Setup()
              .UsePostgreSql(config =&gt; config
                      .ConnectionString(Configuration.GetConnectionString(&quot;&quot;))
                      .Schema(&quot;&quot;)
                      .TableName(&quot;&quot;)
                      .IdColumnName(&quot;&quot;)
                      .DataColumn(&quot;&quot;, DataType.JSONB)
                      .LastUpdatedColumnName(&quot;&quot;);
              );
  </code></pre>
  <p>I've looked through the source code of <strong>UsePostgreSql</strong> - it sets the credentials once so it is not an option to use this extension method.</p>
  <p>Is there any way to configure Audit.NET to obtain database credentials dynamically? Should I implement custom <strong>UsePostgreSql</strong> provider then?</p>