本文整理汇总了C#中Microsoft.Practices.EnterpriseLibrary.SemanticLogging.Formatters.EventTextFormatter.WriteEvent方法的典型用法代码示例。如果您正苦于以下问题:C# EventTextFormatter.WriteEvent方法的具体用法?C# EventTextFormatter.WriteEvent怎么用?C# EventTextFormatter.WriteEvent使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Microsoft.Practices.EnterpriseLibrary.SemanticLogging.Formatters.EventTextFormatter
的用法示例。
在下文中一共展示了EventTextFormatter.WriteEvent方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: WritingToANullWriterThrows
public void WritingToANullWriterThrows()
{
var formatter = new EventTextFormatter();
formatter.WriteEvent(new EventEntry(Guid.NewGuid(), 0, string.Empty, new System.Collections.ObjectModel.ReadOnlyCollection<object>(new object[0]), DateTimeOffset.MaxValue, new EventSourceSchemaReader().GetSchema(Logger).Values.First()), null);
}
示例2: WritingNullEntryThrows
public void WritingNullEntryThrows()
{
var formatter = new EventTextFormatter();
using (var writer = new StringWriter())
{
formatter.WriteEvent(null, writer);
}
}
示例3: WritesNonEmptyRelatedActivityIdOnSummary
public void WritesNonEmptyRelatedActivityIdOnSummary()
{
var formatter = new EventTextFormatter(verbosityThreshold: EventLevel.Critical);
using (var writer = new StringWriter())
{
var relatedActivityId = Guid.NewGuid();
formatter.WriteEvent(
new EventEntry(
Guid.NewGuid(),
0,
string.Empty,
new System.Collections.ObjectModel.ReadOnlyCollection<object>(new object[0]),
DateTimeOffset.MaxValue,
Guid.Empty,
relatedActivityId,
new EventSourceSchemaReader().GetSchema(Logger).Values.First()),
writer);
var message = writer.ToString();
var activityIdMatch = Regex.Match(message, "\\bActivityId : (?<id>[-A-Fa-f0-9]+)\\w?").Groups["id"].Value;
var relatedActivityIdMatch = Regex.Match(message, "\\bRelatedActivityId : (?<id>[-A-Fa-f0-9]+)\\w?").Groups["id"].Value;
Assert.AreEqual(string.Empty, activityIdMatch);
Assert.AreEqual(relatedActivityId.ToString(), relatedActivityIdMatch);
}
}
示例4: WritesProcessIdAndThreadIdOnSummary
public void WritesProcessIdAndThreadIdOnSummary()
{
var formatter = new EventTextFormatter(verbosityThreshold: EventLevel.Critical);
using (var writer = new StringWriter())
{
var processId = 200;
var threadId = 300;
formatter.WriteEvent(
new EventEntry(
Guid.NewGuid(),
0,
string.Empty,
new System.Collections.ObjectModel.ReadOnlyCollection<object>(new object[0]),
DateTimeOffset.MaxValue,
processId,
threadId,
Guid.Empty,
Guid.Empty,
new EventSourceSchemaReader().GetSchema(Logger).Values.First()),
writer);
var message = writer.ToString();
var processIdMatch = Regex.Match(message, "\\bProcessId : (?<id>\\d+)\\w?").Groups["id"].Value;
var threadIdMatch = Regex.Match(message, "\\bThreadId : (?<id>\\d+)\\w?").Groups["id"].Value;
Assert.AreEqual(processId.ToString(), processIdMatch);
Assert.AreEqual(threadId.ToString(), threadIdMatch);
}
}
示例5: InitializeLocalLogging
protected override void InitializeLocalLogging()
{
_platformEventStream = new ObservableEventListener();
_platformEventStream.EnableEvents(EventSources.PlatformSources, TraceLevel);
var formatter = new EventTextFormatter(dateTimeFormat: "O");
_platformEventStream.Subscribe(evt =>
{
StringBuilder b = new StringBuilder();
using (var writer = new StringWriter(b))
{
formatter.WriteEvent(evt, writer);
}
Trace.WriteLine(b.ToString());
});
try
{
var logsResource = RoleEnvironment.GetLocalResource("Logs");
var logFile = Path.Combine(logsResource.RootPath, "Platform", "Platform.log.json");
// Initialize core platform logging
_subscriptions.Add(_platformEventStream.LogToRollingFlatFile(
fileName: logFile,
rollSizeKB: 1024,
timestampPattern: "yyyyMMdd-HHmmss",
rollFileExistsBehavior: RollFileExistsBehavior.Increment,
rollInterval: RollInterval.Hour,
formatter: new JsonEventTextFormatter(EventTextFormatting.Indented, dateTimeFormat: "O"),
maxArchivedFiles: 768, // We have a buffer size of 1024MB for this folder
isAsync: false));
}
catch (Exception ex)
{
ServicePlatformEventSource.Log.FatalException(ex);
throw;
}
}