I have created a small project with Microsoft.ApplicationInsights.NLogTarget with NLog and it is working fine in local. I can see all the event data in my Application Insights resource, no issues at all.
Now, I have tried to move the code to one of my Azure VMs and it has stopped logging to Application Insights completely. I have another target which sends data to a Webhook, working fine from that Azure VM. Only Application Insights target is not working. Any idea?
Please note, this project is already tested locally, but the problem starts when I move it to my Azure VM. No errors in NLog internal log as well. I thought out outbound port rules for my VM but it is logging fine to the external web hook, so internet access is fine. Please suggest the areas to check to get some more clue.
UPDATE: After debugging it in many ways, I have found that the issue is related with CustomTimeZoneTimeSource. I am not sure why, but if I use this then the tracing to Application Insight is completely stopped.
Please note, this is working fine from my VM but when I move to any Azure VM, I had to comment the tag.
<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
throwExceptions="false"
internalLogLevel="Debug"
internalLogFile="C:\Temp\nlog-internal.log">
<extensions>
<add assembly="Microsoft.ApplicationInsights.NLogTarget" />
<!-- This is the project where CustomTimeZone class is created -->
<add assembly="MyApplication.MyProject.Logging" />
</extensions>
<!-- I had to comment the following like to continue logging to Application Insights -->
<time type="CustomTimeZone" zone="Eastern Standard Time" />
<variable name="logDirectory" value="C:\Temp"/>
UPDATE 2: I have just figured out that the issue is with placing the Custom Time source class in a separate class library.
If I place the CustomTimeZoneTimeSource class (AS-IS taken from https://github.com/NLog/NLog/wiki/Time-Source) in the project with Main method, then everything works well, but, if I move the class outside to a different class library then all other targets are showing the new time zone, except Application Insight tracing is getting stopped.
I have posted a question to Application Insights GitHub repository and my sample project is also uploaded in GitHub. Now awaiting feedback....