Пример #1
0
 public void Trace(HttpRequestMessage request, string category, TraceLevel traceLevel,
     Action<TraceRecord> traceAction)
 {
     var record = new TraceRecord(request, category, traceLevel);
     traceAction(record);
     WriteTrace(record);
 }
        /// <inheritdoc />
        public void Log(WT.TraceLevel level, string message, Exception ex)
        {
            if (message == null)
            {
                return;
            }

            switch (level)
            {
            case WT.TraceLevel.Fatal:
            case WT.TraceLevel.Error:
                Trace.TraceError(message);
                break;

            case WT.TraceLevel.Warn:
                Trace.TraceWarning(message);
                break;

            case WT.TraceLevel.Info:
                Trace.TraceInformation(message);
                break;

            case WT.TraceLevel.Debug:
                Trace.WriteLine(message);
                break;

            case WT.TraceLevel.Off:
                break;
            }
        }
Пример #3
0
        public void Trace(HttpRequestMessage request, string category, TraceLevel level, Action<TraceRecord> traceAction)
        {
            if (category == null)
            {
                throw new ArgumentNullException("category");
            }

            if (traceAction == null)
            {
                throw new ArgumentNullException("traceAction");
            }

            if (level < TraceLevel.Off || level > TraceLevel.Fatal)
            {
                throw new ArgumentOutOfRangeException("level");
            }

            TraceRecord traceRecord = new TraceRecord(request, category, level);
            traceAction(traceRecord);
            string message = Format(traceRecord);
            if (!String.IsNullOrEmpty(message))
            {
                _logger.WriteCore(eventType: TraceLevelToTraceEventType[(int)traceRecord.Level], eventId: 0, state: null, exception: traceRecord.Exception, formatter: (_state, _ex) =>
                {
                    return Format(traceRecord);
                });
            }
        }
Пример #4
0
        public void Trace(HttpRequestMessage request, string category, TraceLevel level, Action <TraceRecord> traceAction)
        {
            if (category == null)
            {
                throw new ArgumentNullException("category");
            }

            if (traceAction == null)
            {
                throw new ArgumentNullException("traceAction");
            }

            if (level < TraceLevel.Off || level > TraceLevel.Fatal)
            {
                throw new ArgumentOutOfRangeException("level");
            }

            TraceRecord traceRecord = new TraceRecord(request, category, level);

            traceAction(traceRecord);
            string message = Format(traceRecord);

            if (!String.IsNullOrEmpty(message))
            {
                _logger.WriteCore(eventType: TraceLevelToTraceEventType[(int)traceRecord.Level], eventId: 0, state: null, exception: traceRecord.Exception, formatter: (_state, _ex) =>
                {
                    return(Format(traceRecord));
                });
            }
        }
Пример #5
0
        /// <summary>
        /// Logs to the TraceWriter, if available.
        /// </summary>
        protected void Log(System.Web.Http.Tracing.TraceLevel level, string methodName, string msg)
        {
            msg = "Method: " + methodName + ".  " + msg;//prepend method name
            ITraceWriter tracewriter = Configuration.Services.GetTraceWriter();

            if (tracewriter != null)
            {
                switch (level)
                {
                case System.Web.Http.Tracing.TraceLevel.Error:
                    tracewriter.Error(Request, "", msg);
                    break;

                case System.Web.Http.Tracing.TraceLevel.Warn:
                    tracewriter.Warn(Request, "", msg);
                    break;

                case System.Web.Http.Tracing.TraceLevel.Info:
                    tracewriter.Info(Request, "", msg);
                    break;

                default:
                    tracewriter.Debug(Request, "", msg);
                    break;
                }
            }
        }
Пример #6
0
        public void Trace(HttpRequestMessage request, string category, System.Web.Http.Tracing.TraceLevel level,
                          Action <TraceRecord> traceAction)
        {
            TraceRecord rec = new TraceRecord(request, category, level);

            traceAction(rec);
            WriteTrace(rec);
        }
Пример #7
0
 public void Trace(HttpRequestMessage request, string category, TraceLevel level, Action <TraceRecord> traceAction)
 {
     if (level != TraceLevel.Off)
     {
         var record = new TraceRecord(request, category, level);
         traceAction(record);
         Log(record);
     }
 }
Пример #8
0
        public void Trace(HttpRequestMessage request, string category, System.Web.Http.Tracing.TraceLevel level, Action <System.Web.Http.Tracing.TraceRecord> traceAction)
        {
            TraceRecord rec = new TraceRecord(request, category, level);

            traceAction(rec);
            string message = string.Format("{0};{1};{2}", rec.Operator, rec.Operation, rec.Message);

            System.Diagnostics.Trace.WriteLine(message, rec.Category);
        }
Пример #9
0
        public void Trace(HttpRequestMessage request, string category, System.Web.Http.Tracing.TraceLevel level, Action <System.Web.Http.Tracing.TraceRecord> traceAction)
        {
            // Check if this log level is enabled in our Log4Net settings
            if (level == TraceLevel.Debug && log.IsDebugEnabled == false ||
                level == TraceLevel.Info && (log.IsInfoEnabled == false) ||
                level == TraceLevel.Warn && (log.IsWarnEnabled == false) ||
                level == TraceLevel.Error && (log.IsErrorEnabled == false) ||
                level == TraceLevel.Fatal && (log.IsFatalEnabled == false))
            {
                return;
            }

            // Create trace record and populate details
            var rec = new System.Web.Http.Tracing.TraceRecord(request, category, level);

            traceAction(rec);

            // Change unwanted "Info" traces to Debug
            if (rec.Level == TraceLevel.Info)
            {
                // Operation == "" on the first and last trace message
                if (rec.Operation == null || rec.Operation.Length > 0)
                {
                    rec.Level = TraceLevel.Debug;
                    // Return if we have changed this to debug and Log4Net doesn't have debug enabled
                    if (log.IsDebugEnabled == false)
                    {
                        return;
                    }
                }
            }

            var msg = String.Format("{0} {1} {2}", rec.RequestId, rec.Kind.ToString(), rec.Message);

            switch (rec.Level)
            {
            case TraceLevel.Debug:
                log.Debug(msg);
                break;

            case TraceLevel.Info:
                log.Info(msg);
                break;

            case TraceLevel.Warn:
                log.Warn(msg);
                break;

            case TraceLevel.Error:
                log.Error(msg, rec.Exception);
                break;

            case TraceLevel.Fatal:
                log.Fatal(msg, rec.Exception);
                break;
            }
        }
Пример #10
0
        public void Trace(HttpRequestMessage request,
                          string category,
                          System.Web.Http.Tracing.TraceLevel level,
                          Action <TraceRecord> traceAction)
        {
            var record = new TraceRecord(request, category, level);

            traceAction(record);

            System.Diagnostics.Trace.WriteLine(string.Format("{0} - {1}  {2} - {3}", category, level, record.Kind, record.Operation));
            //WriteTrace(record);
        }
Пример #11
0
 public void Log(System.Web.Http.Tracing.TraceLevel level, string message, Exception ex)
 {
     // LogTrace.Logger.
     if (level == System.Web.Http.Tracing.TraceLevel.Error)
     {
         LogTrace.Error(message, ex);
     }
     else
     {
         LogTrace.Info(message);
     }
     //     Console.WriteLine("test!!!");
 }
Пример #12
0
        public void Trace(HttpRequestMessage request, string category, System.Web.Http.Tracing.TraceLevel level, Action <TraceRecord> traceAction)
        {
            if (level != TraceLevel.Off)
            {
                if (traceAction != null && traceAction.Target != null)
                {
                    category = category + Environment.NewLine + "Action Parameters : " + traceAction.Target.ToString();
                }
                var record = new TraceRecord(request, category, level);
                if (traceAction != null)
                {
                    traceAction(record);
                }
                WriteTrace(record);
                return;
            }


            TraceRecord rec = new TraceRecord(request, category, level);

            traceAction(rec);
            WriteTrace(rec);
        }
 public void Trace(HttpRequestMessage request, string category, System.Web.Http.Tracing.TraceLevel level, Action <System.Web.Http.Tracing.TraceRecord> traceAction)
 {
 }