/// <summary> /// Writes an event message to Application Insights. /// </summary> /// <param name="name">The event name.</param> /// <param name="measurements">The associated measurements.</param> /// <param name="timestamp">The UTC timestamp of the event (default = DateTime.UtcNow).</param> /// <returns><c>true</c> if successfully logged, <c>false</c> otherwise.</returns> public bool WriteEvent( string name, Dictionary <string, double> measurements, DateTime?timestamp = null, string operationName = null, string operationId = null) { if (!this.Log("Event", this._disableEventTracking, this._percentLoggedEvent)) { return(true); } timestamp = timestamp ?? DateTime.UtcNow; var aiEvent = new AiEvent(this.EventProperties, name); var json = this.GetEventJsonString(timestamp.Value, aiEvent, measurements, operationName, operationId); if (this._enableDebug) { this._tracingService.Trace($"DEBUG: Application Insights JSON: {CreateJsonDataLog(json)}"); } return(this.SendToAi(json)); }
private string GetEventJsonString( DateTime timestamp, AiEvent aiEvent, Dictionary <string, double> measurements, string opName, string opid) { var logRequest = new AiLogRequest { Name = $"Microsoft.ApplicationInsights.{this._instrumentationKey}.Event", Time = timestamp.ToString("O"), InstrumentationKey = this._instrumentationKey, Tags = new AiTags { RoleInstance = null, OperationName = opName, OperationId = opid, AuthenticatedUserId = this._authenticatedUserId }, Data = new AiData { BaseType = "EventData", BaseData = aiEvent } }; var json = SerializationHelper.SerializeObject <AiLogRequest>(logRequest); json = InsertMetricsJson(measurements, json); return(json); }
/// <summary> /// Writes an event message to Application Insights. /// </summary> /// <param name="name">The event name.</param> /// <param name="measurements">The associated measurements.</param> /// <param name="timestamp">The UTC timestamp of the event (default = DateTime.UtcNow).</param> /// <returns><c>true</c> if successfully logged, <c>false</c> otherwise.</returns> public bool WriteEvent(string name, Dictionary <string, double> measurements, DateTime?timestamp = null) { if (!Log("Event", _disableEventTracking, _percentLoggedEvent)) { return(true); } timestamp = timestamp ?? DateTime.UtcNow; AiEvent aiEvent = new AiEvent(_eventProperties, name); string json = GetEventJsonString(timestamp.Value, aiEvent, measurements); if (_enableDebug) { _tracingService.Trace($"DEBUG: Application Insights JSON: {CreateJsonDataLog(json)}"); } return(SendToAi(json)); }