本文整理汇总了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;
}
}
示例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());
}
示例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);
}
示例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);
}
示例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();
}
}
}
示例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);
});
}
}
示例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);
}
}
示例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());
}
示例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);
}
}
示例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);
}
示例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 );
}
示例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);
}
示例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);
}
示例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;
}
}
示例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();
}
}
}