当前位置: 首页>>代码示例>>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;未经允许,请勿转载。