Im working for offline posting data to cloud azure. So by editing the dll can i do it?? Is there any way to edit the dll??
Yes, this is possible, but it depends on the situation.
If you are dealing with an application that can sometimes loose its netwerk connectivity then you can use the ServerTelemetryChannel
.
If you want to store the telemetry offline in a central place and have a seperate process send the telemetry to Application Insigths, then no, there is no out-of-the box solution for this. See this question as well.
Now, for the first scenario this will work:
using System;
using System.Threading;
using Microsoft.ApplicationInsights;
using Microsoft.ApplicationInsights.Extensibility;
using Microsoft.ApplicationInsights.WindowsServer.TelemetryChannel;
namespace OfflineApplicationInsights
{
class Program
{
static void Main(string[] args)
{
var upc = new UsingPersistenceChannel();
upc.Log("Test1");
upc.Log("Test2");
upc.Log("Test3");
upc.Log("Test4");
Console.ReadLine();
upc.Flush();
Thread.Sleep(2000);
}
}
public class UsingPersistenceChannel
{
private readonly TelemetryClient _client;
public UsingPersistenceChannel()
{
var config = new TelemetryConfiguration("[your key here]");
var telemetryChannel = new ServerTelemetryChannel
{
StorageFolder = @"C:\Temp\ai-offline",
DeveloperMode = false,
MaxTelemetryBufferCapacity = 1
};
config.TelemetryChannel = telemetryChannel;
telemetryChannel.Initialize(config);
_client = new TelemetryClient(config)
{
InstrumentationKey = "[your key here]"
};
}
public void Log(string msg)
{
_client.TrackTrace(msg);
}
public void Flush()
{
_client.Flush();
}
}
}
But, there is a bug that prevents this from working sometimes. For me, it only works if I disable(!) all network adapters using the Windows configuration panel via Control Panel\Network and Internet\Network Connections
If you would to disable your network and run this program you will see some files appearing in the specified folder. Restore the network and run the application again and you will notice that the files will disappear because they are picked up by the program and send once netwerk activity is detected. At least this is how I tested it.