• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C# Tracing.TraceRecord类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C#中System.Web.Http.Tracing.TraceRecord的典型用法代码示例。如果您正苦于以下问题:C# TraceRecord类的具体用法?C# TraceRecord怎么用?C# TraceRecord使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



TraceRecord类属于System.Web.Http.Tracing命名空间,在下文中一共展示了TraceRecord类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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


示例16: Log

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

            if (!string.IsNullOrWhiteSpace(record.Message))
                message.Append("").Append(record.Message + Environment.NewLine);

            if (record.Request != null)
            {
                if (record.Request.Method != null)
                    message.Append("Method: " + record.Request.Method + Environment.NewLine);

                if (record.Request.RequestUri != null)
                    message.Append("").Append("URL: " + record.Request.RequestUri + Environment.NewLine);

                if (record.Request.Headers != null && record.Request.Headers.Contains("Token") && record.Request.Headers.GetValues("Token") != null && record.Request.Headers.GetValues("Token").FirstOrDefault() != null)
                    message.Append("").Append("Token: " + record.Request.Headers.GetValues("Token").FirstOrDefault() + Environment.NewLine);
            }

            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 (record.Exception != null && !string.IsNullOrWhiteSpace(record.Exception.GetBaseException().Message))
            {
                var exceptionType = record.Exception.GetType();
                message.Append(Environment.NewLine);
                message.Append("").Append("Error: " + record.Exception.GetBaseException().Message + Environment.NewLine);
            }

            Logger[record.Level](Convert.ToString(message) + Environment.NewLine);
        }
开发者ID:kosinovdaniil,项目名称:kosinov-klimchuk-task,代码行数:34,代码来源:NLogger.cs


示例17: Trace

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

            _traces.Enqueue(trace);

            var context = GlobalHost.ConnectionManager.GetConnectionContext<TracePersistentConnection>();
            context.Groups.Send(
                TracePersistentConnection.Authenticated,
                new
                {
                    trace.RequestId,
                    trace.Request.RequestUri,
                    Status = trace.Status.ToString(),
                    Level = trace.Level.ToString(),
                    trace.Message,
                    trace.Category,
                    TimeTicks = trace.Timestamp.Ticks,
                    trace.Operator,
                    trace.Operation,
                    Exception = trace.Exception == null ? "" : trace.Exception.Message,
                });
        }
开发者ID:clegendre,项目名称:webapi.sample.activetrace,代码行数:28,代码来源:TraceWriter.cs


示例18: Log

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

            if (record.Request != null)
            {
                if (record.Request.Method != null)
                    message.Append(record.Request.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.IsNullOrWhiteSpace(record.Exception.GetBaseException().Message))
            message.Append(" ").Append(record.Exception.GetBaseException().Message);

            return string.Format("{0} {1}", record.Level, message);
        }
开发者ID:huoxudong125,项目名称:HQF.Tutorial.WebAPI,代码行数:27,代码来源:PerRequestTraceWriter.cs


示例19: Log

        private void Log(TraceRecord traceRecord) {

            IDependencyScope dependencyScope = traceRecord.Request.GetDependencyScope();
            ILoggerService loggerService = dependencyScope.GetService(typeof(ILoggerService)) as ILoggerService;

            loggerService.Log(new HttpApiLogRecord {
                CorrelationId = traceRecord.RequestId,
                RequestUri = traceRecord.Request.RequestUri.ToString(),
                IpAddress = traceRecord.Request.GetUserHostAddress(),
                HttpMethod = traceRecord.Request.Method.ToString(),
                UserAgent = traceRecord.Request.Headers.UserAgent.ToString(),
                Category = traceRecord.Category,
                Level = traceRecord.Level.ToString(),
                Kind = traceRecord.Kind.ToString(),
                Operator = traceRecord.Operator,
                Operation = traceRecord.Operation,
                ResponseStatusCode = traceRecord.Status.GetHashCode(),
                LogMessage = traceRecord.Message,
                ExceptionType = traceRecord.Exception != null ? traceRecord.Exception.GetType().ToString() : null,
                BaseExceptionType = traceRecord.Exception != null ? traceRecord.Exception.GetBaseException().GetType().ToString() : null,
                ExceptionMessage = traceRecord.Exception != null ? traceRecord.Exception.Message : null,
                ExceptionStackTrace = traceRecord.Exception != null ? traceRecord.Exception.StackTrace : null,
                Timestamp = traceRecord.Timestamp
            });
        }
开发者ID:mahf,项目名称:ASPNETWebAPISamples,代码行数:25,代码来源:WebApiTracer.cs


示例20: Trace

        public override void Trace(System.Net.Http.HttpRequestMessage request, string category, TraceLevel level, Action<TraceRecord> traceAction)
        {
            if (traceAction == null) throw new ArgumentNullException("traceAction");

            var record = new TraceRecord(request, category, level);
            traceAction(record);
            WriteTrace(record);
        }
开发者ID:bfallar3,项目名称:DDD-rebar-demo,代码行数:8,代码来源:RebarTraceWriter.cs



注:本文中的System.Web.Http.Tracing.TraceRecord类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# Mail.MailMessage类代码示例发布时间:2022-05-26
下一篇:
C# Tracing.TestTraceWriter类代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap