本文整理汇总了C#中TraceEventCache类的典型用法代码示例。如果您正苦于以下问题:C# TraceEventCache类的具体用法?C# TraceEventCache怎么用?C# TraceEventCache使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
TraceEventCache类属于命名空间,在下文中一共展示了TraceEventCache类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ProcessIdTest
public void ProcessIdTest()
{
var cache = new TraceEventCache();
var id = cache.ProcessId;
var expected = System.Diagnostics.Process.GetCurrentProcess().Id;
Assert.Equal((int)expected, id);
}
示例2: ShouldTrace
public void ShouldTrace()
{
var cache = new TraceEventCache();
var filter = new EventTypeFilter(SourceLevels.Error);
Assert.True(filter.ShouldTrace(cache, null, TraceEventType.Critical, 0, null, null, null, null));
Assert.False(filter.ShouldTrace(cache, null, TraceEventType.Warning, 0, null, null, null, null));
}
示例3: ThreadIdTest
public void ThreadIdTest()
{
var cache = new TraceEventCache();
var id = cache.ThreadId;
Assert.NotNull(id);
Assert.NotEqual("", id);
}
示例4: TraceData
public override void TraceData(TraceEventCache eventCache, string source, TraceEventType eventType, int id, object data)
{
if (data is LogEntry)
{
this.Write(baseModel.Serialize(new LogMessageModel(data as LogEntry)).DocumentElement.OuterXml);
}
}
示例5: TimestampTest
public void TimestampTest()
{
var cache = new TraceEventCache();
var dt1 = cache.Timestamp;
var dt2 = cache.Timestamp;
Assert.Equal(dt1, dt2);
}
示例6: ShouldTraceTest
public void ShouldTraceTest()
{
var sourceName = "TestSource";
var cache = new TraceEventCache();
var filter = new SourceFilter(sourceName);
Assert.True(filter.ShouldTrace(cache, sourceName, TraceEventType.Critical, 0, null, null, null, null));
Assert.False(filter.ShouldTrace(cache, "Default", TraceEventType.Warning, 0, null, null, null, null));
Assert.Throws<ArgumentNullException>(() => filter.ShouldTrace(cache, null, TraceEventType.Warning, 0, null, null, null, null));
}
示例7: DateTimePropertyTest
public void DateTimePropertyTest()
{
var cache = new TraceEventCache();
var begin = DateTime.UtcNow;
var dt = cache.DateTime;
var end = DateTime.UtcNow;
Assert.True(dt >= begin);
Assert.True(dt <= end);
var cached = cache.DateTime;
Assert.Equal(dt, cached);
}
示例8: TraceEvent_FormatString_Test
public void TraceEvent_FormatString_Test(TraceFilter filter, TraceEventCache eventCache, string source, TraceEventType eventType, int id, string format, object[] args)
{
using (var target = new DelimitedListTraceListener(_stream))
{
target.Filter = filter;
target.TraceOutputOptions = TraceOptions.ProcessId | TraceOptions.ThreadId | TraceOptions.DateTime | TraceOptions.Timestamp;
target.TraceEvent(eventCache, source, eventType, id, format, args);
}
string expected = CommonUtilities.ExpectedTraceEventOutput(filter, eventCache, source, eventType, id, format, args);
Assert.Equal(expected, File.ReadAllText(_fileName));
}
示例9: ExpectedTraceEventOutput
internal static string ExpectedTraceEventOutput(TraceFilter filter, TraceEventCache cache, string source, TraceEventType eventType, int id, string format, object[] args)
{
if (filter != null && !filter.ShouldTrace(cache, source, eventType, id, format, args, null, null))
return string.Empty;
var builder = new StringBuilder();
builder.AppendHeader(source, eventType, id);
builder.Append(EscapedString(args != null ? string.Format(format, args) : format));
builder.Append(DefaultDelimiter);
builder.Append(DefaultDelimiter);
builder.AppendTraceEventCache(cache);
return builder.AppendLine().ToString();
}
示例10: ExpectedTraceDataOutput
internal static string ExpectedTraceDataOutput(TraceFilter filter, TraceEventCache cache, string source, TraceEventType eventType, int id, object data)
{
if (filter != null && !filter.ShouldTrace(cache, source, eventType, id, null, null, data, null))
return string.Empty;
var builder = new StringBuilder();
builder.AppendHeader(source, eventType, id);
builder.Append(DefaultDelimiter);
builder.Append(EscapedString(data.ToString()));
builder.Append(DefaultDelimiter);
builder.AppendTraceEventCache(cache);
return builder.AppendLine().ToString();
}
示例11: LogicalOperationStack
public void LogicalOperationStack()
{
var cache = new TraceEventCache();
var logicalOperationStack = cache.LogicalOperationStack;
Assert.Equal(0, logicalOperationStack.Count);
Trace.CorrelationManager.StartLogicalOperation("SecondaryThread");
Trace.CorrelationManager.StartLogicalOperation("MainThread");
Assert.NotNull(logicalOperationStack);
Assert.Equal(2, logicalOperationStack.Count);
Assert.Equal("MainThread", logicalOperationStack.Pop().ToString());
Assert.Equal("SecondaryThread", logicalOperationStack.Peek().ToString());
Trace.CorrelationManager.StopLogicalOperation();
Assert.Equal(0, logicalOperationStack.Count);
}
示例12: TraceData
public override void TraceData(TraceEventCache eventCache, string source, TraceEventType eventType, int id, object data)
{
if (data is LogEntry)
{
// Check Channel State otherwise can generate loop errors
if (this.proxyLogging.State == CommunicationState.Opened)
{
Guid guid = this.proxyLogging.LoggingExceptionSet(data as LogEntry);
}
}
else
{
//this.WriteLine(data.ToString());
}
}
示例13: AppendTraceEventCache
private static void AppendTraceEventCache(this StringBuilder builder, TraceEventCache cache, string delimiter = DefaultDelimiter)
{
if (cache != null)
{
builder.Append(cache.ProcessId);
builder.Append(delimiter);
builder.Append(EscapedString(cache.ThreadId));
builder.Append(delimiter);
builder.Append(EscapedString(cache.DateTime.ToString("o", CultureInfo.InvariantCulture)));
builder.Append(delimiter);
builder.Append(cache.Timestamp.ToString(CultureInfo.InvariantCulture));
builder.Append(delimiter);
}
else
{
for (int i = 0; i < 5; ++i)
builder.Append(delimiter);
}
}
示例14: TraceEvent
public sealed override void TraceEvent(TraceEventCache eventCache, string source, TraceEventType eventType, int id, string message)
{
if (!_provider.IsEnabled())
{
return;
}
if (Filter != null && !Filter.ShouldTrace(eventCache, source, eventType, id, null, null, null, null))
{
return;
}
StringBuilder dataString = new StringBuilder(s_defaultPayloadSize);
dataString.Append(message);
_provider.WriteMessageEvent(dataString.ToString(),
(byte)eventType,
(long)eventType & s_keyWordMask);
}
示例15: TraceData
public sealed override void TraceData(TraceEventCache eventCache, String source, TraceEventType eventType, int id, params object[] data)
{
if (!_provider.IsEnabled())
{
return;
}
if (Filter != null && !Filter.ShouldTrace(eventCache, source, eventType, id, null, null, null, null))
{
return;
}
int index;
StringBuilder dataString = new StringBuilder(s_defaultPayloadSize);
if ((data != null) && (data.Length > 0))
{
for (index = 0; index < (data.Length - 1); index++)
{
if (data[index] != null)
{
dataString.Append(data[index].ToString());
dataString.Append(Delimiter);
}
else
{
dataString.Append(s_nullStringComaValue);
}
}
if (data[index] != null)
{
dataString.Append(data[index].ToString());
}
else
{
dataString.Append(s_nullStringValue);
}
}
else
{
dataString.Append(s_nullStringValue);
}
_provider.WriteMessageEvent(dataString.ToString(),
(byte)eventType,
(long)eventType & s_keyWordMask);
}