Search code examples
elasticsearchxamarin.formsxamarin.iosserilog

Serilog sinks (the dll files) are no copied in to the iOS app


I'm trying to use Serolog with Serilog.Sinks.Xamarin (v 0.1.37 ) and Serilog.Sinks.Elasticsearch (v 8.0.1) in an Xamarin Forms iOS App. All nugets are installed both in the Xamarin Forms Project as well as in the Xamarin iOS project.

When I try to create the Logger (either in code or from configuration) it fails saying that "Couldn't find file Serilog.Sinks.Elasticsearch". If I remove Serilog.Sinks.Elasticsearch, then it complains about the other one.

I did a little bit of digging and I can see that the Sink dlls are copied in '''\bin\iPhoneSimulator\Debug'''

enter image description here

But they are not present in the app while it is running in the simulator:

enter image description here

Any idea why?


Solution

  • If you add Serilog Sinks and config them in a config file, then create a Serilog config from that file, then create the Serilog logger from the Serilog config ==> there is no direct code anywhere in the App that references the Sinks dlls -> they will be removed from the App. This can happen with any .dlls that are dynamically loaded at runtime. To prevent this, you have to make a dummy call to any function or object from those dlls. In this way there is App code calling them -> they will not be removed.