public void AddLog(SeverityLevel level, string ExceptionMessage, string ExceptionStacktrace, string customMessage) { try { var sqlCom = _db.GetWriteCommand( @"INSERT INTO logs ( LogLevel, ExceptionMessage, ExceptionStacktrace, CustomMessage, Date ) Values ( @LogLevel, @ExceptionMessage, @ExceptionStacktrace, @CustomMessage, @Date );" ); sqlCom.Parameters.AddWithValue( "@LogLevel", level.ToString() ); sqlCom.Parameters.AddWithValue( "@ExceptionMessage", ExceptionMessage ); sqlCom.Parameters.AddWithValue( "@ExceptionStacktrace", ExceptionStacktrace ); sqlCom.Parameters.AddWithValue( "@CustomMessage", customMessage ); sqlCom.Parameters.AddWithValue( "@Date", DateTime.Now ); sqlCom.ExecuteNonQuery(); } finally { _db.CloseConnections(); } }
/// <summary> /// Similar to event viewer. Filter out the events based on <paramref name="severityLevel"/> is what we are interested in here. /// </summary> /// <param name="eventSource">The event source name</param> /// <param name="correlationClientTrackingId">The correlation tracking id of the workflow run</param> /// <param name="message">The message to be displayed</param> /// <param name="severityLevel">The severity level</param> public void TrackTrace(string eventSource, string correlationClientTrackingId, string message, SeverityLevel severityLevel) { if (!SeverityLevelHelper.IsAllowedForLogging(severityLevel, this.MimimumLogginglevel)) { return; } try { Dictionary <string, object> properties = new Dictionary <string, object> { { Constants.IntegrationAccountTrackingApiConstants.OmsMesssage, message } }; this.managementEndPoint.PostCustomTrackingEvents( eventSource, correlationClientTrackingId, severityLevel.ToString(), DateTime.UtcNow.ToString("O"), new Dictionary <string, object>(), properties); } catch (Exception) { if (this.ThrowTrackingException) { throw; } } }
public static Label Severity(SeverityLevel value) { return(new Label() { name = "severity", value = value.ToString() }); }
public void AddLog(SeverityLevel level, string ExceptionMessage, string ExceptionStacktrace, string customMessage) { try { var sqlCom = _db.GetWriteCommand(@"INSERT INTO logs ( LogLevel, ExceptionMessage, ExceptionStacktrace, CustomMessage, Date ) Values ( @LogLevel, @ExceptionMessage, @ExceptionStacktrace, @CustomMessage, @Date );"); sqlCom.Parameters.AddWithValue("@LogLevel", level.ToString()); sqlCom.Parameters.AddWithValue("@ExceptionMessage", ExceptionMessage); sqlCom.Parameters.AddWithValue("@ExceptionStacktrace", ExceptionStacktrace); sqlCom.Parameters.AddWithValue("@CustomMessage", customMessage); sqlCom.Parameters.AddWithValue("@Date", DateTime.Now); sqlCom.ExecuteNonQuery(); } finally { _db.CloseConnections(); } }
public void AddLog(SeverityLevel level, string ExceptionMessage, string ExceptionStacktrace, string customMessage) { var sqlCom = GetWriteCommand(@"INSERT INTO logs ( LogLevel, ExceptionMessage, ExceptionStacktrace, CustomMessage, Date ) Values ( @LogLevel, @ExceptionMessage, @ExceptionStacktrace, @CustomMessage, @Date );"); sqlCom.Parameters.AddWithValue("@LogLevel", level.ToString()); sqlCom.Parameters.AddWithValue("@ExceptionMessage", ExceptionMessage); sqlCom.Parameters.AddWithValue("@ExceptionStacktrace", ExceptionStacktrace); sqlCom.Parameters.AddWithValue("@CustomMessage", customMessage); sqlCom.Parameters.AddWithValue("@Date", Utils.GetGermanNow()); sqlCom.ExecuteNonQuery(); }
public void LogException(Exception ex, SeverityLevel severityLevel) { if (Log != null) { switch (severityLevel) { case SeverityLevel.Critical: Log.Error(string.Format("{0} {1}", severityLevel.ToString().ToUpper(), ex.Message), ex); break; case SeverityLevel.Fatal: Log.Fatal(string.Format("{0} {1}", severityLevel.ToString().ToUpper(), ex.Message), ex); break; default: Log.Info(string.Format("{0} {1}", severityLevel.ToString().ToUpper(), ex.Message), ex); break; } } }
private static void ValidateTelemetry(ITelemetry telemetry, string expectedInvocationId, string expectedOperationName, string expectedCategory, SeverityLevel expectedLevel) { Assert.Equal(expectedInvocationId, ((ISupportProperties)telemetry).Properties[LogConstants.InvocationIdKey]); Assert.Equal(expectedOperationName, telemetry.Context.Operation.Name); ISupportProperties properties = (ISupportProperties)telemetry; Assert.Equal(expectedCategory, properties.Properties[LogConstants.CategoryNameKey]); Assert.Equal(expectedLevel.ToString(), properties.Properties[LogConstants.LogLevelKey]); }
/// <summary> /// Convert the severity to a recognizable String category /// of Glimpse. /// </summary> /// <param name="severity">Severity level of telemetry. </param> /// <returns> Glimpse category </returns> public static string SeverityToCategory(SeverityLevel severity) { switch (severity) { case SeverityLevel.Error: return "error"; case SeverityLevel.Information: return "info"; case SeverityLevel.Warning: return "warn"; default: return severity.ToString(); } }
public void Log(string message, SeverityLevel severityLevel) { if (LogToConsole) { if (severityLevel != SeverityLevel.Verbose) { Console.WriteLine(DateTime.Now + " [" + severityLevel.ToString() + "] - " + message); } } if (tc != null) { tc.TrackTrace(message, SeverityLevel.Verbose); } }
/// <summary> /// Use to track exceptions. The frequency of the exception and examining their individual occurrences is what we are interested in here. /// </summary> /// <param name="eventSource">The event source name</param> /// <param name="correlationClientTrackingId">The correlation tracking id of the workflow run</param> /// <param name="message">The message to be displayed</param> /// <param name="severityLevel">The severity level</param> /// <param name="exception">The exception</param> public void TrackException(string eventSource, string correlationClientTrackingId, string message, SeverityLevel severityLevel, Exception exception) { if (!SeverityLevelHelper.IsAllowedForLogging(severityLevel, this.MimimumLogginglevel)) { return; } try { Dictionary <string, object> trackedExceptions = new Dictionary <string, object> { { Constants.IntegrationAccountTrackingApiConstants.OmsCorrelationTrackingId, correlationClientTrackingId }, { Constants.IntegrationAccountTrackingApiConstants.OmsMesssage, message }, { Constants.IntegrationAccountTrackingApiConstants.OmsSeverityLevel, severityLevel.ToString() }, { Constants.IntegrationAccountTrackingApiConstants.OmsExceptionType, exception.GetType().ToString() }, { Constants.IntegrationAccountTrackingApiConstants.OmsExceptionMesssage, exception.Message }, { Constants.IntegrationAccountTrackingApiConstants.OmsExceptionStackTrace, exception.StackTrace } }; var aggregateException = exception as AggregateException; if (aggregateException != null) { var i = 0; foreach (Exception innerException in aggregateException.InnerExceptions) { trackedExceptions.Add($"{Constants.IntegrationAccountTrackingApiConstants.OmsInnerExceptionType}_{i}", innerException.GetType().ToString()); trackedExceptions.Add($"{Constants.IntegrationAccountTrackingApiConstants.OmsInnerExceptionMesssage}_{i}", innerException.Message); trackedExceptions.Add($"{Constants.IntegrationAccountTrackingApiConstants.OmsInnerExceptionStackTrace}_{i}", innerException.StackTrace); i++; } } this.managementEndPoint.PostCustomTrackingEvents( eventSource, correlationClientTrackingId, severityLevel.ToString(), DateTime.UtcNow.ToString("O"), new Dictionary <string, object>(), trackedExceptions); } catch (Exception) { if (this.ThrowTrackingException) { throw; } } }
private void PushMessage(string message, SeverityLevel severityLevel) { if (string.Equals(ConfigurationManager.Instance.Get <TelemetryClientConfiguration>().SinkType, SinkType.Console.ToString())) { Console.WriteLine($"Message: { message},SeverityLevel: {severityLevel.ToString()}"); } else { client.TrackTrace(message, severityLevel, new Dictionary <string, string>() { { "RootActivityId", ServiceContext.CurrentContext._correlationContext?.RootActivityId }, { "SessionId", ServiceContext.CurrentContext._correlationContext?.SessionId }, { "Application", ServiceContext.CurrentContext._correlationContext?.Application } }); } }
internal static void WriteOutput(SeverityLevel severityLevel, string message, params object[] parameters) { if (parameters != null && parameters.Length > 0) { message = string.Format(CultureInfo.InvariantCulture, message, parameters); } Telemetry.TrackTrace(message, severityLevel); if (severityLevel != SeverityLevel.Information) { message = string.Format(CultureInfo.InvariantCulture, "{0}: {1}", severityLevel.ToString(), message); } Console.WriteLine(message); }
/// <summary> /// Convert the severity to a recognizable String category /// of Glimpse. /// </summary> /// <param name="severity">Severity level of telemetry. </param> /// <returns> Glimpse category </returns> public static string SeverityToCategory(SeverityLevel severity) { switch (severity) { case SeverityLevel.Error: return("error"); case SeverityLevel.Information: return("info"); case SeverityLevel.Warning: return("warn"); default: return(severity.ToString()); } }
public void Log(SeverityLevel level, string message, object owner, Exception exception = null) { var msg = this.FormatMessage(message, owner); if ((int)this.LogLevel <= (int)level) { switch (level) { case SeverityLevel.Debug: this.Debug(msg, owner); break; case SeverityLevel.Info: this.Info(msg, owner); break; case SeverityLevel.Audit: this.Audit($"Audit: {msg}", owner); break; case SeverityLevel.Warn: this.Warn(msg, owner, exception); break; case SeverityLevel.Error: this.Error(msg, owner, exception); break; case SeverityLevel.Fatal: this.Fatal(msg, owner, exception); break; default: throw new NotSupportedException($"Log level '{level.ToString()}' is not supported."); } } }
public static void Log(object message, SeverityLevel severityLevel = SeverityLevel.Info) { Debug.WriteLine($"{message} \t#time: {DateTime.Now.TimeOfDay}", severityLevel.ToString()); }
/// <summary> /// Use to track exceptions. The frequency of the exception and examining their individual occurrences is what we are interested in here. /// </summary> /// <param name="eventSource">The event source name</param> /// <param name="correlationClientTrackingId">The correlation tracking id of the workflow run</param> /// <param name="message">The message to be displayed</param> /// <param name="severityLevel">The severity level</param> /// <param name="exception">The exception</param> public void TrackException(string eventSource, string correlationClientTrackingId, string message, SeverityLevel severityLevel, Exception exception) { if (!SeverityLevelHelper.IsAllowedForLogging(severityLevel, this.MimimumLogginglevel)) { return; } try { Dictionary <string, object> trackedExceptions = new Dictionary <string, object> { { Constants.OMSTrackingAPIConstants.SourceEventSourceName, eventSource }, { $"{Constants.OMSTrackingAPIConstants.SourceRunInstance}{Constants.OMSTrackingAPIConstants.OmsCorrelationTrackingId}", correlationClientTrackingId }, { $"{Constants.OMSTrackingAPIConstants.Event}{Constants.OMSTrackingAPIConstants.OmsEventLevel}", severityLevel.ToString() }, { $"{Constants.OMSTrackingAPIConstants.EventRecord}{Constants.OMSTrackingAPIConstants.OmsMesssage}", message }, { $"{Constants.OMSTrackingAPIConstants.EventRecord}{Constants.OMSTrackingAPIConstants.OmsExceptionType}", exception.GetType().ToString() }, { $"{Constants.OMSTrackingAPIConstants.EventRecord}{Constants.OMSTrackingAPIConstants.OmsExceptionMesssage}", exception.Message }, { $"{Constants.OMSTrackingAPIConstants.EventRecord}{Constants.OMSTrackingAPIConstants.OmsExceptionStackTrace}", exception.StackTrace } }; var aggregateException = exception as AggregateException; if (aggregateException != null) { var i = 0; foreach (Exception innerException in aggregateException.InnerExceptions) { trackedExceptions.Add($"{Constants.OMSTrackingAPIConstants.EventRecord}{Constants.OMSTrackingAPIConstants.OmsInnerExceptionType}_{i}", innerException.GetType().ToString()); trackedExceptions.Add($"{Constants.OMSTrackingAPIConstants.EventRecord}{Constants.OMSTrackingAPIConstants.OmsInnerExceptionMesssage}_{i}", innerException.Message); trackedExceptions.Add($"{Constants.OMSTrackingAPIConstants.EventRecord}{Constants.OMSTrackingAPIConstants.OmsInnerExceptionStackTrace}_{i}", innerException.StackTrace); i++; } } this.dataCollector.Collect(this.LogType, trackedExceptions); } catch (Exception) { if (this.ThrowTrackingException) { throw; } } }
public static Label Severity(SeverityLevel value) { return(new Label { name = "severity", value = value.ToString().ToLowerInvariant() }); }
public static void Write(string message, string source, SeverityLevel level) { Console.WriteLine(source + " : " + level.ToString().ToLower() + " 1: " + message); }
public static Label Severity(SeverityLevel value) => new Label() { name = "severity", value = value.ToString() };
/// <summary> /// Similar to event viewer. Filter out the events based on <paramref name="severityLevel"/> is what we are interested in here. /// </summary> /// <param name="eventSource">The event source name</param> /// <param name="correlationClientTrackingId">The correlation tracking id of the workflow run</param> /// <param name="message">The message to be displayed</param> /// <param name="severityLevel">The severity level</param> /// <param name="properties">The properties to be added along with the message</param> public void TrackTrace(string eventSource, string correlationClientTrackingId, string message, SeverityLevel severityLevel, IDictionary <string, object> properties) { if (!SeverityLevelHelper.IsAllowedForLogging(severityLevel, this.MimimumLogginglevel)) { return; } try { Dictionary <string, object> trackTraces = new Dictionary <string, object> { { Constants.OMSTrackingAPIConstants.SourceEventSourceName, eventSource }, { $"{Constants.OMSTrackingAPIConstants.SourceRunInstance}{Constants.OMSTrackingAPIConstants.OmsCorrelationTrackingId}", correlationClientTrackingId }, { $"{Constants.OMSTrackingAPIConstants.EventRecord}{Constants.OMSTrackingAPIConstants.OmsEventLevel}", severityLevel.ToString() }, { $"{Constants.OMSTrackingAPIConstants.EventRecord}{Constants.OMSTrackingAPIConstants.OmsMesssage}", message } }; foreach (KeyValuePair <string, object> property in properties) { trackTraces.Add($"{Constants.OMSTrackingAPIConstants.EventRecord}{property.Key}", property.Value); } this.dataCollector.Collect(this.LogType, trackTraces); } catch (Exception) { if (this.ThrowTrackingException) { throw; } } }