ApplicationInsights-dotnet icon indicating copy to clipboard operation
ApplicationInsights-dotnet copied to clipboard

Package update replaces log configuration in app.config

Open Muhomorik opened this issue 6 years ago • 12 comments

Hello,

This is an old issue that happens every time one update Microsoft.ApplicationInsights.NLogTarget. app.config rules are replaced with default ones.

I've just updated from 2.6.4 to 2.8.2 and got this change.

appinsights

Muhomorik avatar Oct 16 '18 07:10 Muhomorik

Complexity here is that we want to remove logger from config on uninstall:

https://github.com/Microsoft/ApplicationInsights-dotnet-logging/blob/93ad4a8a46965d95654fe1f962df74c3bb792a79/src/NLogTarget/app.config.uninstall.xdt#L10-L12

NuGet will call uninstall first and then install the never package. There is no indication given that uninstall is a part of an upgrade.

One solution may be to switch attribute Enable to false on uninstall instead. But this will not help you =).

Do you have better suggestion on how to fix it?

SergeyKanzhelev avatar Oct 19 '18 16:10 SergeyKanzhelev

@karann-msft , I found your name in NuGet repo. Can you please confirm that there is no way to detect whether uninstall was called for upgrade or by itself?

SergeyKanzhelev avatar Oct 19 '18 17:10 SergeyKanzhelev

@SergeyKanzhelev - no, its not possible to differentiate between those two. cc: @jainaashish

karann-msft avatar Oct 19 '18 21:10 karann-msft

So we either have a bug on in-proper clean up of a config or a bug on erasing customizations. I think first is more critical as not erasing listeners may be damaging for the application and hard to discover. When erasing of customizations is easily discoverable via and source control system.

Closing the issue unless there are better proposals. @Muhomorik thank you for reporting and using Application Insights!

SergeyKanzhelev avatar Oct 19 '18 21:10 SergeyKanzhelev

This problem is obviously solved by nlog and apparently there is a way to figure out if this is an upgrade:

PM> Update-Package Nlog.Config
... etc...

File Conflict
File 'NLog.config' already exists in project 'VbWinFormsNlog'. Do you want to overwrite it?
[Y] Yes  [A] Yes to All  [N] No  [L] No to All  [?] Help (default is "N"): N

When erasing of customizations is easily discoverable via and source control system.

Not how a source control should be used. Imaging solution with 20 projects.

I think first is more critical as not erasing listeners may be damaging for the application and hard to discover.

Yes, but you are enabling listeners on TRACE level. From docs: Trace | Begin method X, end method X etc

Most programs have checkbox "allow reporting errors etc", but this is completely different. This is like possible GDRP violation because debug data will be send.

Also, I am talking about "Classic desktop". Means that you can't update all installations that quickly.

Plus, I believe the default config for loggers is not to create any listeners at all.

Muhomorik avatar Oct 24 '18 06:10 Muhomorik

@karann-msft, @jainaashish any suggestions here? Do you know how NLog package does it?

SergeyKanzhelev avatar Nov 06 '18 06:11 SergeyKanzhelev

NLog also hasn't solved. NLog.config was modified after first installation so when we uninstalled as part of update, we left it behind. Now as part of install NuGet sees the file already exists so it ask to overwrite before proceeding.

If NLog.Config wasn't modified before then it would not have shown this overwriting option. So simply install NLog.config and try to update.

jainaashish avatar Nov 06 '18 17:11 jainaashish

Another poor soul bitten by this "feature":

https://usefulscripts.wordpress.com/2020/05/10/use-application-insights-logging-adapters-with-nlog-c-console-application/

Btw. the NLog.config-nuget-package should be avoided at all costs. It will actually give you more headache (After Microsoft introduced <packagereferences> in csproj-files).

snakefoot avatar May 25 '20 20:05 snakefoot

This issue is stale because it has been open 300 days with no activity. Remove stale label or comment or this will be closed in 7 days.

github-actions[bot] avatar Sep 21 '21 00:09 github-actions[bot]

Stil think this "feature" should be removed. The idea was it should help with initial setup, but actually it is causing a lot of pain during deployment with unexpected surprises. Don't like unexpected surprises.

snakefoot avatar Sep 25 '21 10:09 snakefoot

This issue is stale because it has been open 300 days with no activity. Remove stale label or this will be closed in 7 days. Commenting will instruct the bot to automatically remove the label.

github-actions[bot] avatar Jul 23 '22 00:07 github-actions[bot]

Still bad behavior to modify config-files on nuget-package install.

snakefoot avatar Jul 23 '22 05:07 snakefoot

This issue is stale because it has been open 300 days with no activity. Remove stale label or this will be closed in 7 days. Commenting will instruct the bot to automatically remove the label.

github-actions[bot] avatar May 21 '23 00:05 github-actions[bot]