Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to change Table Storage conn string at runtime #48

Open
fergus3000 opened this issue Sep 20, 2019 · 1 comment
Open

Unable to change Table Storage conn string at runtime #48

fergus3000 opened this issue Sep 20, 2019 · 1 comment

Comments

@fergus3000
Copy link

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!

@snakefoot
Copy link
Contributor

snakefoot commented Sep 20, 2019

I guess changes could be made, so it delays the initialization from ConnectionString, until the it is actually available (without failing).

But if you change the connection-string after having loaded the NLog-config, then you can try one of these approaches:

https://github.com/NLog/NLog/wiki/Reinitialize-NLog-configuration

But the easy solution is just to use ${configsetting:Logging.TableStorageConnStr} and ensure to have loaded appsetting.json before loading NLog.config. See also https://github.com/NLog/NLog/wiki/ConfigSetting-Layout-Renderer

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants