Ejemplo n.º 1
0
 /// <summary>
 /// Trace an event
 /// </summary>
 public void TraceEvent(System.Diagnostics.Tracing.EventLevel level, string format, params Object[] args)
 {
     foreach (var w in this.m_writers)
     {
         w.TraceEvent(level, this.m_source, format, args);
     }
 }
Ejemplo n.º 2
0
 /// <summary>
 /// Trace an event
 /// </summary>
 public void TraceEvent(System.Diagnostics.Tracing.EventLevel level, string format, params Object[] args)
 {
     foreach (var w in m_writers.ToArray())
     {
         //    if (level <= w.Value || w.Value == EventLevel.LogAlways)
         w.Key.TraceEvent(level, this.m_source, format, args);
     }
 }
Ejemplo n.º 3
0
        public static void InitializeLogger(string instanceName, System.Diagnostics.Tracing.EventLevel logEventLevel, string connectionString, string applicationName = "NA")
        {
            var logListener1 = new ObservableEventListener();

            logListener1.EnableEvents(AppEventSourceManager.Log, logEventLevel, EventKeywords.None);

            logListener1.LogToSqlDatabase(instanceName, connectionString, "Traces", Buffering.DefaultBufferingInterval, 1, Timeout.InfiniteTimeSpan, 500);

            AppEventSourceManager.Log.Info(string.Format("Logger Initialized - Event Source : {0}, Log Level : {1}", instanceName, logEventLevel.ToString()), applicationName);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Write the trace to the log file
        /// </summary>
        /// <param name="level">Level.</param>
        /// <param name="source">Source.</param>
        /// <param name="format">Format.</param>
        /// <param name="args">Arguments.</param>
        protected override void WriteTrace(System.Diagnostics.Tracing.EventLevel level, string source, string format, params object[] args)
        {
            lock (this.m_logBacklog)
            {
                this.m_logBacklog.Enqueue(String.Format("{0}@{1} <{2}> [{3:o}]: {4}", source, Thread.CurrentThread.Name, level, DateTime.Now, String.Format(format, args)));
                //string dq = String.Format("{0}@{1} <{2}> [{3:o}]: {4}", source, Thread.CurrentThread.Name, level, DateTime.Now, String.Format(format, args));
                //using (TextWriter tw = File.AppendText(this.m_logFile))
                //    tw.WriteLine(dq); // This allows other threads to add to the write queue

                Monitor.Pulse(this.m_logBacklog);
            }
        }
Ejemplo n.º 5
0
 /// <summary>
 /// Write the trace to the log file
 /// </summary>
 /// <param name="level">Level.</param>
 /// <param name="source">Source.</param>
 /// <param name="format">Format.</param>
 /// <param name="args">Arguments.</param>
 protected override void WriteTrace(System.Diagnostics.Tracing.EventLevel level, string source, string format, params object[] args)
 {
     try
     {
         using (TextWriter tw = File.AppendText(this.m_logFile))
             tw.WriteLine("{0}@{1} <{2}> [{3:o}]: {4}", source, Thread.CurrentThread.Name, level, DateTime.Now, String.Format(format, args)); // This allows other threads to add to the write queue
     }
     catch
     {
         ;
     }
 }
Ejemplo n.º 6
0
        public ConsoleColor?Map(System.Diagnostics.Tracing.EventLevel eventLevel)
        {
            switch (eventLevel)
            {
            case EventLevel.Critical:
                return(ConsoleColor.White);

            case EventLevel.Error:
                return(ConsoleColor.DarkMagenta);

            case EventLevel.Warning:
                return(ConsoleColor.DarkYellow);

            case EventLevel.Verbose:
                return(ConsoleColor.Blue);

            default:
                return(null);
            }
        }
Ejemplo n.º 7
0
        public static void InitializeLogger(string instanceName, System.Diagnostics.Tracing.EventLevel logEventLevel, string applicationName = "NA")
        {
            var logListener1 = new ObservableEventListener();

            logListener1.EnableEvents(AppEventSourceManager.Log, logEventLevel, EventKeywords.None);

            logListener1.LogToSqlDatabase(instanceName,
                                          ConfigurationManager.ConnectionStrings["DefaultConnection"].ConnectionString,
                                          "Traces",
                                          Microsoft.Practices.EnterpriseLibrary.SemanticLogging.Utility.Buffering.DefaultBufferingInterval,
                                          1,
                                          Timeout.InfiniteTimeSpan,
                                          500);

            //var logListener2 = new ObservableEventListener();
            //logListener2.EnableEvents(IoTEventSourceManager.Log, logEventLevel, EventKeywords.None);

            //logListener2.LogToFlatFile("semanticLogs.json", new JsonEventTextFormatter(EventTextFormatting.Indented), true);

            AppEventSourceManager.Log.Info(string.Format("Logger Initialized - Event Source : {0}, Log Level : {1}", instanceName, logEventLevel.ToString()), applicationName);
        }