private void BuildCustomProperties(LoggingEvent loggingEvent, ITelemetry trace) { trace.Timestamp = loggingEvent.TimeStamp; trace.Context.User.Id = loggingEvent.UserName; IDictionary <string, string> properties; if (trace is ExceptionTelemetry) { properties = ((ExceptionTelemetry)trace).Properties; } else { properties = ((TraceTelemetry)trace).Properties; } ApplicationInsightsAppender.AddLoggingEventProperty("LoggerName", loggingEvent.LoggerName, properties); ApplicationInsightsAppender.AddLoggingEventProperty("ThreadName", loggingEvent.ThreadName, properties); LocationInfo locationInformation = loggingEvent.LocationInformation; if (locationInformation != null) { ApplicationInsightsAppender.AddLoggingEventProperty("ClassName", locationInformation.ClassName, properties); ApplicationInsightsAppender.AddLoggingEventProperty("FileName", locationInformation.FileName, properties); ApplicationInsightsAppender.AddLoggingEventProperty("MethodName", locationInformation.MethodName, properties); ApplicationInsightsAppender.AddLoggingEventProperty("LineNumber", locationInformation.LineNumber, properties); } ApplicationInsightsAppender.AddLoggingEventProperty("Domain", loggingEvent.Domain, properties); ApplicationInsightsAppender.AddLoggingEventProperty("Identity", loggingEvent.Identity, properties); var properties2 = loggingEvent.Properties; //PropertiesDictionary properties2 = loggingEvent.GetProperties(); if (properties2 != null) { string[] keys = properties2.GetKeys(); for (int i = 0; i < keys.Length; i++) { string text = keys[i]; if (!string.IsNullOrEmpty(text) && !text.StartsWith("log4net", StringComparison.OrdinalIgnoreCase)) { object obj = properties2[text]; if (obj != null) { ApplicationInsightsAppender.AddLoggingEventProperty(text, obj.ToString(), properties); } } } } }
/// <summary> /// Initializes the Appender and perform instrumentationKey validation. /// </summary> public override void ActivateOptions() { base.ActivateOptions(); this.telemetryClient = new TelemetryClient(); //TODO: in config this.telemetryClient.Context.InstrumentationKey = Sitecore.Configuration.Settings.GetSetting("InstrumentationKey"); //if (!string.IsNullOrEmpty(config.InstrumentationKey)) //{ // this.telemetryClient.Context.InstrumentationKey = config.InstrumentationKey; //} this.telemetryClient.Context.GetInternalContext().SdkVersion = "Log4Net: " + ApplicationInsightsAppender.GetAssemblyVersion(); }