NLog.Extensions.AzureStorage
NLog.Extensions.AzureStorage copied to clipboard
Unable to change Table Storage conn string at runtime
I find that once I have configured the table store via nlog.config, I am unable to then modify the connection string at runtime.
I'm attempting to update the connection string by doing something like the following:
var tableStoreTgt = LogManager.Configuration.AllTargets.FirstOrDefault(t => t.GetType() == typeof(TableStorageTarget)) as TableStorageTarget;
tableStoreTgt.ConnectionString = _configuration["Logging:TableStorageConnStr"];
LogManager.ReconfigExistingLoggers();
A similar technique works for say an NLog Database target
Viewing this in debugger shows that the TableStorageTarget's ConnectionString property does get updated, however the target's inner _cloudTableService member's CloudTableClient still retains the original connection string info
I'm doing it this way because I want to configure my cloud endpoint info and loglevel using Azure App Configuration, but at the same time I find the nlog.config gives a clearer idea of the intended logging format and rules.
I suppose that adding a new target programatically would allow me to make this dynamic, but it would break the pattern of configuring as much as possible from the nlog config file. I didn't really want to set a connection string at all in the config file, but the nlog target wouldn't initialize without a valid string present.
Btw thank you for implementing these targets, it's generally a great extension!