當前位置: 首頁>>代碼示例>>C#>>正文


C# Tracing.TraceRecord類代碼示例

本文整理匯總了C#中System.Web.Http.Tracing.TraceRecord的典型用法代碼示例。如果您正苦於以下問題:C# TraceRecord類的具體用法?C# TraceRecord怎麽用?C# TraceRecord使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


TraceRecord類屬於System.Web.Http.Tracing命名空間,在下文中一共展示了TraceRecord類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: WriteTrace

        protected void WriteTrace(TraceRecord record)
        {
            var message = string.Format("{0};{1};{2}", record.Operator, record.Operation, record.Message);
            //System.Diagnostics.Trace.WriteLine(message, record.Category);
            System.Diagnostics.Trace.WriteLine(message, record.Category);

            switch (record.Level)
            {
                case TraceLevel.Error:
                    _traceSource.TraceEvent(TraceEventType.Error, 0, message);
                    break;
                case TraceLevel.Fatal:
                    _traceSource.TraceEvent(TraceEventType.Critical, 0, message);
                    break;
                case TraceLevel.Warn:
                    _traceSource.TraceEvent(TraceEventType.Warning, 0, message);
                    break;
                case TraceLevel.Debug:
                    _traceSource.TraceEvent(TraceEventType.Verbose, 0, message);
                    break;
                default:
                    _traceSource.TraceEvent(TraceEventType.Information, 0, message); //record.Request
                    break;
            }
        }
開發者ID:vip32,項目名稱:eventfeedback,代碼行數:25,代碼來源:TraceSourceWriter.cs

示例2: Trace

        public void Trace(HttpRequestMessage request, string category, TraceLevel level, Action<TraceRecord> traceAction)
        {
            var record = new TraceRecord(request, category, level);
            traceAction(record);

            var sb = new StringBuilder();
            if (record.Request != null)
            {
                if (record.Request.Method != null)
                {
                    sb.Append(" ");
                    sb.Append(request.Method.ToString());
                }
                if (record.Request.RequestUri != null)
                {
                    sb.Append(" ");
                    sb.Append(record.Request.RequestUri.ToString());
                }
                if (!string.IsNullOrWhiteSpace(record.Category))
                {
                    sb.Append(" ");
                    sb.Append(record.Category);
                }
                sb.Append(" ");
                sb.Append(record.Message);

                if (record.Exception != null)
                {
                    sb.Append(record.Exception.ToString());
                }
            }
            Console.WriteLine(sb.ToString());
        }
開發者ID:jkells,項目名稱:WebAppHost,代碼行數:33,代碼來源:WindsorConfiguration.cs

示例3: WriteTrace

 protected void WriteTrace(TraceRecord rec)
 {
     var message = string.Format("{0};{1};{2}",
         rec.Operator, rec.Operation, rec.Message);
     //System.Diagnostics.Trace.WriteLine(message, rec.Category);
     log.TraceFormat("Category {0} - {1}", rec.Category,message);
 }
開發者ID:megadotnet,項目名稱:ironframework,代碼行數:7,代碼來源:LoggingTracer.cs

示例4: Trace

 public void Trace(HttpRequestMessage request, string category, TraceLevel traceLevel,
     Action<TraceRecord> traceAction)
 {
     var record = new TraceRecord(request, category, traceLevel);
     traceAction(record);
     WriteTrace(record);
 }
開發者ID:iv0m,項目名稱:WebApi2BestSheds,代碼行數:7,代碼來源:SimpleTraceWriter.cs

示例5: AddTrace

        /// <summary>
        /// Adds a single trace record to the store.
        /// </summary>
        /// <remarks>
        /// All trace records are correlated with their associated
        /// request GUID inside this method.
        /// </remarks>
        /// <param name="traceRecord"></param>
        public void AddTrace(TraceRecord traceRecord)
        {
            lock (_thisLock)
            {
                RequestTrace requestTrace;
                if (_requestList.Count >= _maxRequests)
                {
                    requestTrace = _requestList.Last.Value;
                    _requestList.RemoveLast();
                    _requestDictionary.Remove(requestTrace.Id);
                }

                if (!_requestDictionary.TryGetValue(traceRecord.RequestId.ToString(), out requestTrace))
                {
                    requestTrace = CreateRequestTrace(traceRecord);
                    _requestDictionary[requestTrace.Id] = requestTrace;
                    _requestList.AddFirst(requestTrace);
                }

                TraceItem traceItem = CreateTraceItem(traceRecord);
                requestTrace.Traces.Add(traceItem);
                if (traceItem.Status != 0)
                {
                    requestTrace.Status = traceItem.Status;
                    requestTrace.Reason = ((HttpStatusCode) traceItem.Status).ToString();
                }
            }
        }
開發者ID:mdabbagh88,項目名稱:ODataServer,代碼行數:36,代碼來源:MemoryTraceStore.cs

示例6: Trace

        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);
                });
            }
        }
開發者ID:RolandTG,項目名稱:OwinSamples,代碼行數:28,代碼來源:OwinWebApiTracer.cs

示例7: Trace

        public void Trace(HttpRequestMessage request, string category, TraceLevel level, Action<TraceRecord> traceAction)
        {
            if (request != null)
            {
                var traceQueryString = request.GetQueryString("trace"); ;

                bool shouldTrace;
                if (traceQueryString != null &&  Boolean.TryParse(traceQueryString, out shouldTrace)&& shouldTrace)
            {
                    object perRequestTrace;
                    if (!request.Properties.TryGetValue("perRequestTrace", out perRequestTrace))
                    {
                        perRequestTrace = new List<string>();
                        request.Properties["perRequestTrace"] = perRequestTrace;
                    }

                    var record = new TraceRecord(request, category, level);
                    traceAction(record);
                    (perRequestTrace as List<string>).Add(Log(record));
                }
            }

            if (_innerWriter != null)
            {
                _innerWriter.Trace(request, category, level, traceAction);
            }
        }
開發者ID:huoxudong125,項目名稱:HQF.Tutorial.WebAPI,代碼行數:27,代碼來源:PerRequestTraceWriter.cs

示例8: Log

        private void Log(TraceRecord record)
        {
            var message = new StringBuilder();

            if (record.Request != null)
            {
                if (record.Request.Method != null)
                    message.Append(" ").Append(record.Request.Method.Method);

                if (record.Request.RequestUri != null)
                    message.Append(" ").Append(record.Request.RequestUri.AbsoluteUri);
            }

            if (!string.IsNullOrWhiteSpace(record.Category))
                message.Append(" ").Append(record.Category);

            if (!string.IsNullOrWhiteSpace(record.Operator))
                message.Append(" ").Append(record.Operator).Append(" ").Append(record.Operation);

            if (!string.IsNullOrWhiteSpace(record.Message))
                message.Append(" ").Append(record.Message);
                  
            if (record.Exception != null && !string.IsNullOrEmpty(record.Exception.GetBaseException().Message))
                message.Append(" ").AppendLine(record.Exception.GetBaseException().Message);

            Logger[record.Level](message.ToString());
        }
開發者ID:BoomTownROI,項目名稱:WebApiContrib.Tracing.Log4Net,代碼行數:27,代碼來源:Log4NetTraceWriter.cs

示例9: Trace

        public void Trace(HttpRequestMessage request, string category, TraceLevel level, Action<TraceRecord> traceAction)
        {
            if (TraceSwitcher.Level == TraceSwitcher.TraceLevel.None)
                return;

            if (request == null)
                return;

            var rec = new TraceRecord(request, category, level);
            traceAction(rec);
            AddTraceData(request, rec);

            if (!IsRequestFinishing(rec))
                return;

            var traceData = GetTraceData(request);
            if (traceData != null)
            {
                ComputeSummaryData(traceData);

                if (TraceSwitcher.Level == TraceSwitcher.TraceLevel.Error
                    && traceData.Exception == null)
                {
                    return;
                }

                OnRequestFinish(traceData);
            }
        }
開發者ID:atanashristov,項目名稱:WebApiTrace,代碼行數:29,代碼來源:TraceWriterBase.cs

示例10: WriteTrace

 protected void WriteTrace(TraceRecord rec)
 {
     var message = string.Format("{0};{1};{2}",
                                 rec.Operator, rec.Operation, rec.Message);
     System.Diagnostics.Trace.WriteLine(message, rec.Category);
     Log.Debug(rec.Category + " " + message);
 }
開發者ID:polyzois,項目名稱:VsdependecyEdit,代碼行數:7,代碼來源:SimpleTracer.cs

示例11: StartTrace

        /// <summary>
        /// Performs the start trace operation.
        /// </summary>
        /// <param name="traceRecord">The <see cref="TraceRecord">trace record</see> associated with the operation.</param>
        public void StartTrace( TraceRecord traceRecord )
        {
            Arg.NotNull( traceRecord, nameof( traceRecord ) );

            Start();
            startTrace( traceRecord );
        }
開發者ID:WaffleSquirrel,項目名稱:More,代碼行數:11,代碼來源:TraceStopwatch.cs

示例12: Trace

        public void Trace(HttpRequestMessage request, string category, TraceLevel level, Action<TraceRecord> traceAction)
        {
            var record = new TraceRecord(request, category, level);
            traceAction(record);

            System.Diagnostics.Trace.TraceInformation("{0} {1} {2}", category, level, record.Message);
        }
開發者ID:jacktsai,項目名稱:ApiFoundation,代碼行數:7,代碼來源:TraceWriter.cs

示例13: Log

        private void Log(TraceRecord record)
        {
            var message = string.Empty;

            if (record.Request != null)
            {
                if (record.Request.Method != null)
                    message += " " + record.Request.Method.ToString();

                if (record.Request.RequestUri != null)
                    message += " " + record.Request.RequestUri.ToString();
            }

            if (!string.IsNullOrWhiteSpace(record.Category))
                message += " " + record.Category;

            if (!string.IsNullOrWhiteSpace(record.Operator))
                message += " " + record.Operator + " " + record.Operation;

            if (!string.IsNullOrWhiteSpace(record.Message))
                message += " " + record.Message;

            if (record.Exception != null)
            {
                if (record.Exception.GetBaseException().Message != null)
                    message += record.Exception.GetBaseException().Message;
            }

            _logger[record.Level](message);
        }
開發者ID:deanogorman,項目名稱:Our-Bloody-Project,代碼行數:30,代碼來源:NLogger.cs

示例14: Trace

        public void Trace(HttpRequestMessage request, string category, TraceLevel level, Action<TraceRecord> traceAction)
        {
            // set nlog logger - note: this category is bypassed; the logger name in the log event info is used instead
            var logger = LogManager.GetLogger(category);

            try
            {
                // only log and trace if enabled
                var logLevel = GetLogLevel(level);
                if (logger.IsEnabled(logLevel))
                {
                    // setup trace record
                    var record = new TraceRecord(request, category, level);

                    // user traces and populates record
                    traceAction(record);

                    // create the log event and log  - this will log to the configured nlog target, rules, etc. specified by the app
                    logger.Log(CreateEvent(record, logLevel));
                }
            }
            catch(Exception e)
            {
                // log exception - this exception usually occurs within the user's trace action code                
                logger.LogException(LogLevel.Error, "Failed to trace message due to an error.", e);
                throw;
            }
        }
開發者ID:kfrancis,項目名稱:webapi.nlog,代碼行數:28,代碼來源:NLogTraceWriter.cs

示例15: WriteXmlElement

        private void WriteXmlElement(TraceRecord rec)
        {
            using (Stream xmlFile = new FileStream(@"D:\Ari Gunawan\Belajar\WEB API\Code\Apress.PracticalWebApi.HelloWebApi\log.xml", FileMode.Append))
            {
                using (XmlTextWriter writer = new XmlTextWriter(xmlFile, Encoding.UTF8))
                {
                    writer.Formatting = Formatting.Indented;
                    writer.WriteStartElement("trace");
                    writer.WriteElementString("timestamp", rec.Timestamp.ToString());
                    writer.WriteElementString("operation", rec.Operation);
                    writer.WriteElementString("user", rec.Operator);

                    if (!String.IsNullOrWhiteSpace(rec.Message))
                    {
                        writer.WriteStartElement("message");
                        writer.WriteCData(rec.Message);
                        writer.WriteEndElement();
                    }

                    writer.WriteElementString("category", rec.Category);
                    writer.WriteEndElement();
                    writer.WriteString(Environment.NewLine);
                    writer.Flush();
                }
            }
        }
開發者ID:kuboconcept,項目名稱:Apress.PracticalWebApi.HelloWebApi,代碼行數:26,代碼來源:WebApiTracer.cs


注:本文中的System.Web.Http.Tracing.TraceRecord類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。