.NET Core Fallback Logging

I have two 3rd-party logging providers in my ASP.NET Core GRPC Service. Can I somehow "chain" these logging providers? I mean, can logging provider 2 perform logging only in situations when logging provider 1 failed to log. For example, if I have an Application Insights provider and NLog File provider, can I log into the file only if my service can't connect to Application Insights infrastructure?


You can do everything mentioned using different NLog targets. So there is a target for Azure Application Insight: https://www.nuget.org/packages/Microsoft.ApplicationInsights.NLogTarget/.

Moreover if you have doubts that some of your targets can proceed slowly you can use asynchronous logging for it: https://github.com/NLog/NLog/wiki/AsyncWrapper-target


In my humble opinion, setting some rule to make 2 kinds of logging providers work like a chain is not necessary and maybe impossible.

What we usually do is making them work at the same time, just like using NLog to write log to files and send log to azure application insights as well.

By the way, azure application insight may not work because of some accident, but it's a small probability event. The scenario that the logging module not working is more likely to be the application crashed, then all the modules in your application are down including both the logging modules. So even have the feature to make Nlog work when application insight doesn't work, it's high probably to have a result that when application insight doesn't work, Nlog can't work too.