本文整理汇总了C#中System.Diagnostics.TraceEventCache类的典型用法代码示例。如果您正苦于以下问题:C# TraceEventCache类的具体用法?C# TraceEventCache怎么用?C# TraceEventCache使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
TraceEventCache类属于System.Diagnostics命名空间,在下文中一共展示了TraceEventCache类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TraceEvent
public override void TraceEvent(TraceEventCache eventCache, string source, TraceEventType eventType, int id, string format, params object[] args)
{
if (args == null || args.Length == 0)
Append(eventType, format);
else
Append(eventType, String.Format(format, args));
}
示例2: TraceData
public override void TraceData(TraceEventCache eventCache, string source, TraceEventType eventType, int id, object data)
{
tracedData = data;
tracedSource = source;
tracedEventType = eventType;
entries.Add(data as LogEntry);
}
示例3: Write
public void Write(LogEntry entry, Type filterListener)
{
Guard.ArgumentNotNull(entry, "entry");
TraceEventCache manager = new TraceEventCache();
foreach(TraceListener listener in this.Listeners)
{
bool lockTaken = false;
try
{
if (!listener.IsThreadSafe)
{
Monitor.Enter(sync, ref lockTaken);
}
if (filterListener == null ||
filterListener == listener.GetType())
{
listener.TraceData(manager, string.Empty, entry.Severity, 0, entry);
listener.Flush();
}
}
finally
{
if (!listener.IsThreadSafe && lockTaken)
{
Monitor.Exit(sync);
}
}
}
}
示例4: TraceEvent
public override sealed void TraceEvent(TraceEventCache eventCache, string source, TraceEventType eventType, int id, string message)
{
if ((base.Filter == null) || base.Filter.ShouldTrace(eventCache, source, eventType, id, message, null, null, null))
{
WriteTrace(eventCache, source, eventType, id, message, null, null);
}
}
示例5: TraceEvent
public override void TraceEvent(TraceEventCache eventCache, string source, TraceEventType eventType, int id, string format, params object[] args)
{
if (Filter != null && !Filter.ShouldTrace(eventCache, source, eventType, id, format, args, null, null))
{
return;
}
var client = new SmtpClient(Settings.Default.SmtpServer)
{
Credentials = new NetworkCredential(Settings.Default.SmtpUsername, Settings.Default.SmtpPassword),
EnableSsl = true
};
var body = string.Format(format, args);
var firstLine = new StringReader(body).ReadLine();
if (firstLine.Length > 100)
{
firstLine = firstLine.Substring(0, 97).Trim() + "...";
}
var msg = new MailMessage
{
From = new MailAddress(Settings.Default.NotificationFrom, "FitBot"),
To = {Settings.Default.NotificationTo},
Subject = $"{eventType} - {firstLine}",
Body = body
};
client.Send(msg);
}
示例6: ShouldTrace
/// <summary>
/// Determines whether a filter is attached to this listener and, if so, asks whether it ShouldTrace applies to this data.
/// </summary>
protected virtual bool ShouldTrace(TraceEventCache eventCache, string source, TraceEventType eventType, int id,
string formatOrMessage, object[] args, object data1, object[] data)
{
return
!(Filter != null &&
!Filter.ShouldTrace(eventCache, source, eventType, id, formatOrMessage, args, data1, data));
}
示例7: TraceEvent
public override void TraceEvent(TraceEventCache eventCache, string source, TraceEventType eventType, int id)
{
var te = new TraceEvent {Cache = eventCache, Source = source, Type = eventType, Id = id};
Events.Add(te);
if (OnEventAdd != null)
OnEventAdd.Invoke(te);
}
示例8: TraceData
public override void TraceData(TraceEventCache eventCache, string source, TraceEventType eventType, int id, object data)
{
LogMessage msg = (LogMessage)data;
byte[] buf = FormatMessage(string.Concat(msg.MessageAsText, "\n"));
Stream.Write(buf, 0, buf.Length); // Write message buffer
Stream.Flush();
}
示例9: TraceEvent
public override void TraceEvent (TraceEventCache eventCache, string source, TraceEventType severity, int id, string message)
{
if (HttpContext.Current == null || HttpContext.Current.Trace == null)
return;
HttpContext.Current.Trace.Write (source, message);
}
示例10: TraceEvent
public override void TraceEvent(TraceEventCache eventCache, string source, TraceEventType eventType, int id, string format, params object[] args)
{
lock (_sync)
{
if(Filter != null && !Filter.ShouldTrace(eventCache, source, eventType, id, format, args, null, null)) return;
ConsoleColor color;
switch (eventType)
{
case TraceEventType.Error:
color = ConsoleColor.Red;
break;
case TraceEventType.Warning:
color = ConsoleColor.Yellow;
break;
case TraceEventType.Information:
color = ConsoleColor.Green;
break;
case TraceEventType.Verbose:
color = ConsoleColor.DarkCyan;
break;
default:
color = ConsoleColor.Gray;
break;
}
var eventTypeString = Enum.GetName(typeof (TraceEventType), eventType);
var message = source + " - " + eventTypeString + " > " + (args.Length > 0 ? string.Format(format, args): format);
WriteColor(message + Environment.NewLine, color);
}
}
示例11: TraceEvent
public override void TraceEvent(TraceEventCache eventCache, string source, TraceEventType eventType, int id, string format, params object[] args)
{
string message = string.Format(format, args);
// write the localised date and time but include the time zone in brackets (good for combining logs from different timezones)
TimeSpan utcOffset = TimeZone.CurrentTimeZone.GetUtcOffset(DateTime.Now);
string plusOrMinus = (utcOffset < TimeSpan.Zero) ? "-" : "+";
string utcHourOffset = utcOffset.TotalHours == 0 ? string.Empty : string.Format(" ({0}{1:hh})", plusOrMinus, utcOffset);
string dateWithOffset = string.Format(@"{0:yyyy/MM/dd HH:mm:ss.fff}{1}", DateTime.Now, utcHourOffset);
// display the threadid
string log = string.Format(@"{0} [{1}] {2}", dateWithOffset, Thread.CurrentThread.ManagedThreadId, message);
switch (eventType)
{
case TraceEventType.Critical:
case TraceEventType.Error:
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine(log);
Console.ResetColor();
break;
case TraceEventType.Warning:
Console.ForegroundColor = ConsoleColor.Yellow;
Console.WriteLine(log);
Console.ResetColor();
break;
default:
Console.WriteLine(log);
break;
}
}
示例12: TraceEvent
/// <summary>
/// Traces the message. Supported event types are: Critical, Error, Information and Warning.
/// </summary>
public override void TraceEvent(TraceEventCache eventCache, string source, TraceEventType eventType, int id, string message)
{
if (Logger != null)
{
switch (eventType)
{
case TraceEventType.Critical:
{
Logger.Fatal(message);
}
break;
case TraceEventType.Error:
{
Logger.Error(message);
}
break;
case TraceEventType.Information:
{
Logger.Info(message);
}
break;
case TraceEventType.Warning:
{
Logger.Warn(message);
}
break;
}
}
}
示例13: TraceData
/// <summary>
/// Forwards the trace request to the wrapped listener.
/// </summary>
/// <param name="eventCache">The context information.</param>
/// <param name="source">The trace source.</param>
/// <param name="severity">The severity.</param>
/// <param name="id">The event id.</param>
/// <param name="data">The objects to trace.</param>
public override void TraceData(TraceEventCache eventCache, string source, TraceEventType severity, int id, params object[] data)
{
if ((this.Filter == null) || this.Filter.ShouldTrace(eventCache, source, severity, id, null, null, null, data))
{
this.innerListener.TraceData(eventCache, source, severity, id, data);
}
}
示例14: WriteEvent
public void WriteEvent(string message, string source, TraceEventType type) {
var ctx = BeforeWriteEvent();
try {
if (source == null) {
source = s_processFileName;
}
var evtId = Interlocked.Increment(ref _evtId);
var evtCache = new TraceEventCache();
foreach (TraceListener l in listeners) {
lock (l) {
try {
l.TraceEvent(evtCache, source, type, evtId, message);
if (Trace.AutoFlush) {
l.Flush();
}
} catch {
//swallow error
Debugger.Break();
}
}
}
} finally {
AfterWriteEvent(ctx);
}
}
示例15: TraceEvent
public override void TraceEvent(TraceEventCache eventCache, string source, TraceEventType eventType, int id)
{
if (_enabled)
{
WebSocketHost.Send($"{eventType}:{id} - {source}");
}
}