コード例 #1
0
ファイル: LoggerDatabase.cs プロジェクト: Epstone/remindii
        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();
              }
        }
コード例 #2
0
        /// <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;
                }
            }
        }
コード例 #3
0
 public static Label Severity(SeverityLevel value)
 {
     return(new Label()
     {
         name = "severity", value = value.ToString()
     });
 }
コード例 #4
0
        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();
            }
        }
コード例 #5
0
ファイル: UtilDatabase.cs プロジェクト: Epstone/mypvlog
        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();
        }
コード例 #6
0
 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;
         }
     }
 }
コード例 #7
0
        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]);
        }
コード例 #8
0
 /// <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();
     }
 }
コード例 #9
0
        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);
            }
        }
コード例 #10
0
        /// <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;
                }
            }
        }
コード例 #11
0
 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 }
         });
     }
 }
コード例 #12
0
        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);
        }
コード例 #13
0
        /// <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());
            }
        }
コード例 #14
0
ファイル: LogProvider.cs プロジェクト: vhil/vohil-diagnostics
        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.");
                }
            }
        }
コード例 #15
0
 public static void Log(object message, SeverityLevel severityLevel = SeverityLevel.Info)
 {
     Debug.WriteLine($"{message} \t#time: {DateTime.Now.TimeOfDay}", severityLevel.ToString());
 }
コード例 #16
0
        /// <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;
                }
            }
        }
コード例 #17
0
 public static Label Severity(SeverityLevel value)
 {
     return(new Label {
         name = "severity", value = value.ToString().ToLowerInvariant()
     });
 }
コード例 #18
0
ファイル: Log.cs プロジェクト: davelondon/dontstayin
		public static void Write(string message, string source, SeverityLevel level)
		{
			Console.WriteLine(source + " : " + level.ToString().ToLower() + " 1: " + message);
			
		}
コード例 #19
0
 public static Label Severity(SeverityLevel value) => new Label()
 {
     name = "severity", value = value.ToString()
 };
コード例 #20
0
        /// <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;
                }
            }
        }