public static void UseLogging(this IAppBuilder app, HttpConfiguration config) { const string instrumentationKeySettingName = "Telemetry.AI.InstrumentationKey"; var instrumentationKey = ConfigurationManager.AppSettings[instrumentationKeySettingName]; TelemetryConfiguration.Active.InstrumentationKey = instrumentationKey; EventListener = ApplicationInsightsLog.CreateListener(instrumentationKey); EventListener.EnableEvents("SpikeCo-Platform-HostLifecycle", EventLevel.LogAlways, EventKeywords.All); EventListener.EnableEvents("MyCompany-Application1-WebApi3", EventLevel.LogAlways, EventKeywords.All); }
private string FormatMessage(ApplicationInsightsLog log, Exception ex) { var exceptionMessage = string.Empty; if (ex != null) { exceptionMessage = $" - Exception Message: {ex.Message}"; } return($"{log.Name} - {log.Message}{exceptionMessage}"); }
public void GivenAiTelemetryAndDefaultEntryTypeShouldWriteEntry() { const string source = "source"; const string message = "message"; EventType eventType = new EventType(); LogAuthorFake logAuthorFake = new LogAuthorFake(); ApplicationInsightsLog applicationInsightsLog = new ApplicationInsightsLog(logAuthorFake); applicationInsightsLog.WriteEntry(source, message, eventType); logAuthorFake.LogEntries().Count.Should().Be(1); logAuthorFake.LogEntries().First().Source().Should().Be(source); logAuthorFake.LogEntries().First().Message().Should().Be(message); logAuthorFake.LogEntries().First().EventType().Should().Be(eventType); }