本文整理汇总了C#中Result.ToJson方法的典型用法代码示例。如果您正苦于以下问题:C# Result.ToJson方法的具体用法?C# Result.ToJson怎么用?C# Result.ToJson使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Result
的用法示例。
在下文中一共展示了Result.ToJson方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TraceResult
private static void TraceResult(string ruleId, string message, Exception exception, Level messageLevel)
{
IRuleDescriptor rule = SarifTraceListener.Rules.Where(r => r.Id.Equals(ruleId, StringComparison.OrdinalIgnoreCase)).FirstOrDefault();
// Create a result for the rule.
Result result = new Result();
result.RuleId = rule == null ? ruleId : rule.Id;
result.ShortMessage = message;
result.FullMessage = message;
switch (messageLevel)
{
case Level.Information:
result.Kind = ResultKind.Note;
break;
case Level.Warning:
result.Kind = ResultKind.Warning;
break;
case Level.Error:
default:
result.Kind = ResultKind.Error;
break;
}
if (exception != null)
{
result.FullMessage += Environment.NewLine + Environment.NewLine + exception.ToString();
result.Stacks = exception.ToCodeLocations();
}
// Add some properties about the machine.
result.Properties = new Dictionary<string, string>();
result.Properties["Machine"] = Environment.MachineName;
result.Properties["ThreadId"] = System.Threading.Thread.CurrentThread.ManagedThreadId.ToString();
result.Properties["EventTime"] = DateTime.Now.ToUniversalTime().ToString();
result.Properties["Application"] = System.Reflection.Assembly.GetEntryAssembly() != null ? Path.GetFileName(System.Reflection.Assembly.GetEntryAssembly().Location) : null;
result.Properties["ProcessId"] = System.Diagnostics.Process.GetCurrentProcess().Id.ToString();
string json = result.ToJson();
// Write to the log.
switch (messageLevel)
{
case Level.Information:
StatusTrace.TraceInformation(result.FullMessage, json);
break;
case Level.Warning:
StatusTrace.TraceWarning(result.FullMessage, json);
break;
case Level.Error:
default:
StatusTrace.TraceError(result.FullMessage, json);
break;
}
}