1
votes

I am using the ServiceEventSource implementation that comes with VS template to log messages. It appears in Diagnostics event viewer but not in the configured application insights instance. I do get other platform events in application insights instance but not my application logging.

Example log line -

ServiceEventSource.Current.ServiceMessage(this.Context, "Config deployment is disabled.");

I haven't done anything other than using configuring application insights using Visual studio context menu. Also when creating the service fabric cluster I did provide the right instrumentation key.

ApplicationInsights.config -

<?xml version="1.0" encoding="utf-8"?>
<ApplicationInsights xmlns="http://schemas.microsoft.com/ApplicationInsights/2013/Settings">
  <InstrumentationKey>ac5a18e4-3750-46b4-ac10-2a887915b163</InstrumentationKey>
  <TelemetryInitializers>
    <Add Type="Microsoft.ApplicationInsights.ServiceFabric.FabricTelemetryInitializer, Microsoft.AI.ServiceFabric"/>
  </TelemetryInitializers>
  <TelemetryModules>
    <Add Type="Microsoft.ApplicationInsights.ServiceFabric.Module.ServiceRemotingRequestTrackingTelemetryModule, Microsoft.AI.ServiceFabric.Native"/>
    <Add Type="Microsoft.ApplicationInsights.Extensibility.PerfCounterCollector.QuickPulse.QuickPulseTelemetryModule, Microsoft.AI.PerfCounterCollector"/>
  </TelemetryModules>
  <TelemetryProcessors>
    <Add Type="Microsoft.ApplicationInsights.Extensibility.PerfCounterCollector.QuickPulse.QuickPulseTelemetryProcessor, Microsoft.AI.PerfCounterCollector"/>
  </TelemetryProcessors>
</ApplicationInsights>

Program.cs-

using System;
using System.Diagnostics;
using System.Fabric;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.ServiceFabric.Services.Runtime;

namespace ConfigUploadService
{
    internal static class Program
    {
        /// <summary>
        /// This is the entry point of the service host process.
        /// </summary>
        private static void Main()
        {
            try
            {
                // The ServiceManifest.XML file defines one or more service type names.
                // Registering a service maps a service type name to a .NET type.
                // When Service Fabric creates an instance of this service type,
                // an instance of the class is created in this host process.

                ServiceRuntime.RegisterServiceAsync("ConfigUploadServiceType",
                    context => new ConfigUploadService(context)).GetAwaiter().GetResult();

                ServiceEventSource.Current.ServiceTypeRegistered(Process.GetCurrentProcess().Id, typeof(ConfigUploadService).Name);

                // Prevents this host process from terminating so services keep running.
                Thread.Sleep(Timeout.Infinite);
            }
            catch (Exception e)
            {
                ServiceEventSource.Current.ServiceHostInitializationFailed(e.ToString());
                throw;
            }
        }
    }
}

What am I missing ?

1

1 Answers

2
votes

The default template you used are targeted to telemetry events, your application EventSource events is unknown to App Insights monitor, so you have to setup a pipeline for these events to tell that these events belongs to your application and you want to log them on AppInsights.

You can see them on diagnostics window, because VS register then when you debug your app.

I assume that what your are looking for is described in this link: service-fabric-diagnostics-event-aggregation-eventflow

Event Flow will give you the tools to do it with same flexibility as you did for telemetry events.