本文整理汇总了C#中ErrorLogger.LogDiagnostic方法的典型用法代码示例。如果您正苦于以下问题:C# ErrorLogger.LogDiagnostic方法的具体用法?C# ErrorLogger.LogDiagnostic怎么用?C# ErrorLogger.LogDiagnostic使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ErrorLogger
的用法示例。
在下文中一共展示了ErrorLogger.LogDiagnostic方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: DescriptorIdCollision
public void DescriptorIdCollision()
{
var descriptors = new[] {
// Toughest case: generation of TST001-001 collides with with actual TST001-001 and must be bumped to TST001-002
new DiagnosticDescriptor("TST001-001", "_TST001-001_", "", "", DiagnosticSeverity.Warning, true),
new DiagnosticDescriptor("TST001", "_TST001_", "", "", DiagnosticSeverity.Warning, true),
new DiagnosticDescriptor("TST001", "_TST001-002_", "", "", DiagnosticSeverity.Warning, true),
new DiagnosticDescriptor("TST001", "_TST001-003_", "", "", DiagnosticSeverity.Warning, true),
// Descriptors with same values should not get distinct entries in log
new DiagnosticDescriptor("TST002", "", "", "", DiagnosticSeverity.Warning, true),
new DiagnosticDescriptor("TST002", "", "", "", DiagnosticSeverity.Warning, true),
// Changing only the message format (which we do not write out) should not produce a distinct entry in log.
new DiagnosticDescriptor("TST002", "", "messageFormat", "", DiagnosticSeverity.Warning, true),
// Changing any property that we do write out should create a distinct entry
new DiagnosticDescriptor("TST002", "title_001", "", "", DiagnosticSeverity.Warning, true),
new DiagnosticDescriptor("TST002", "", "", "category_002", DiagnosticSeverity.Warning, true),
new DiagnosticDescriptor("TST002", "", "", "", DiagnosticSeverity.Error /*003*/, true),
new DiagnosticDescriptor("TST002", "", "", "", DiagnosticSeverity.Warning, isEnabledByDefault: false /*004*/),
new DiagnosticDescriptor("TST002", "", "", "", DiagnosticSeverity.Warning, true, "description_005"),
};
var stream = new MemoryStream();
using (var logger = new ErrorLogger(stream, "toolName", "1.2.3.4", new Version(1, 2, 3, 4), new CultureInfo("en-US")))
{
for (int i = 0; i < 2; i++)
{
foreach (var descriptor in descriptors)
{
logger.LogDiagnostic(Diagnostic.Create(descriptor, Location.None));
}
}
}
string expected =
@"{
""$schema"": ""http://json.schemastore.org/sarif-1.0.0"",
""version"": ""1.0.0"",
""runs"": [
{
""tool"": {
""name"": ""toolName"",
""version"": ""1.2.3.4"",
""fileVersion"": ""1.2.3.4"",
""semanticVersion"": ""1.2.3"",
""language"": ""en-US""
},
""results"": [
{
""ruleId"": ""TST001-001"",
""level"": ""warning"",
""properties"": {
""warningLevel"": 1
}
},
{
""ruleId"": ""TST001"",
""level"": ""warning"",
""properties"": {
""warningLevel"": 1
}
},
{
""ruleId"": ""TST001"",
""ruleKey"": ""TST001-002"",
""level"": ""warning"",
""properties"": {
""warningLevel"": 1
}
},
{
""ruleId"": ""TST001"",
""ruleKey"": ""TST001-003"",
""level"": ""warning"",
""properties"": {
""warningLevel"": 1
}
},
{
""ruleId"": ""TST002"",
""level"": ""warning"",
""properties"": {
""warningLevel"": 1
}
},
{
""ruleId"": ""TST002"",
""level"": ""warning"",
""properties"": {
""warningLevel"": 1
}
},
{
""ruleId"": ""TST002"",
""level"": ""warning"",
""message"": ""messageFormat"",
""properties"": {
""warningLevel"": 1
//.........这里部分代码省略.........
示例2: AdditionalLocationsAsRelatedLocations
public void AdditionalLocationsAsRelatedLocations()
{
var stream = new MemoryStream();
using (var logger = new ErrorLogger(stream, "toolName", "1.2.3.4", new Version(1, 2, 3, 4), new CultureInfo("fr-CA")))
{
var span = new TextSpan(0, 0);
var position = new LinePositionSpan(LinePosition.Zero, LinePosition.Zero);
var mainLocation = Location.Create(@"Z:\Main Location.cs", span, position);
var descriptor = new DiagnosticDescriptor("TST", "_TST_", "", "", DiagnosticSeverity.Error, false);
IEnumerable<Location> additionalLocations = new[] {
Location.Create(@"Relative Additional\Location.cs", span, position),
Location.Create(@"a:cannot/interpret/as\uri", span, position),
};
logger.LogDiagnostic(Diagnostic.Create(descriptor, mainLocation, additionalLocations));
}
string expected =
@"{
""$schema"": ""http://json.schemastore.org/sarif-1.0.0"",
""version"": ""1.0.0"",
""runs"": [
{
""tool"": {
""name"": ""toolName"",
""version"": ""1.2.3.4"",
""fileVersion"": ""1.2.3.4"",
""semanticVersion"": ""1.2.3"",
""language"": ""fr-CA""
},
""results"": [
{
""ruleId"": ""TST"",
""level"": ""error"",
""locations"": [
{
""resultFile"": {
""uri"": ""file:///Z:/Main%20Location.cs"",
""region"": {
""startLine"": 1,
""startColumn"": 1,
""endLine"": 1,
""endColumn"": 1
}
}
}
],
""relatedLocations"": [
{
""physicalLocation"": {
""uri"": ""Relative%20Additional/Location.cs"",
""region"": {
""startLine"": 1,
""startColumn"": 1,
""endLine"": 1,
""endColumn"": 1
}
}
},
{
""physicalLocation"": {
""uri"": ""a%3Acannot%2Finterpret%2Fas%5Curi"",
""region"": {
""startLine"": 1,
""startColumn"": 1,
""endLine"": 1,
""endColumn"": 1
}
}
}
]
}
],
""rules"": {
""TST"": {
""id"": ""TST"",
""shortDescription"": ""_TST_"",
""defaultLevel"": ""error"",
""properties"": {
""isEnabledByDefault"": false
}
}
}
}
]
}";
string actual = Encoding.UTF8.GetString(stream.ToArray());
Assert.Equal(expected, actual);
}
示例3: DescriptorIdCollision
public void DescriptorIdCollision()
{
var descriptors = new[] {
new DiagnosticDescriptor("TST001.001", "_TST001.001_", "", "", DiagnosticSeverity.Warning, true),
new DiagnosticDescriptor("TST001", "_TST001_", "", "", DiagnosticSeverity.Warning, true),
new DiagnosticDescriptor("TST001", "_TST001.002_", "", "", DiagnosticSeverity.Warning, true),
new DiagnosticDescriptor("TST001", "_TST001.003_", "", "", DiagnosticSeverity.Warning, true),
};
var stream = new MemoryStream();
using (var logger = new ErrorLogger(stream, "toolName", "1.2.3.4", new Version(1, 2, 3, 4), CultureInfo.InvariantCulture))
{
for (int i = 0; i < 2; i++)
{
foreach (var descriptor in descriptors)
{
logger.LogDiagnostic(Diagnostic.Create(descriptor, Location.None));
}
}
}
string expected =
@"{
""$schema"": ""http://json.schemastore.org/sarif-1.0.0-beta.5"",
""version"": ""1.0.0-beta.5"",
""runs"": [
{
""tool"": {
""name"": ""toolName"",
""version"": ""1.2.3.4"",
""fileVersion"": ""1.2.3.4"",
""semanticVersion"": ""1.2.3""
},
""results"": [
{
""ruleId"": ""TST001.001"",
""level"": ""warning"",
""properties"": {
""warningLevel"": 1
}
},
{
""ruleId"": ""TST001"",
""level"": ""warning"",
""properties"": {
""warningLevel"": 1
}
},
{
""ruleId"": ""TST001"",
""ruleKey"": ""TST001.002"",
""level"": ""warning"",
""properties"": {
""warningLevel"": 1
}
},
{
""ruleId"": ""TST001"",
""ruleKey"": ""TST001.003"",
""level"": ""warning"",
""properties"": {
""warningLevel"": 1
}
},
{
""ruleId"": ""TST001.001"",
""level"": ""warning"",
""properties"": {
""warningLevel"": 1
}
},
{
""ruleId"": ""TST001"",
""level"": ""warning"",
""properties"": {
""warningLevel"": 1
}
},
{
""ruleId"": ""TST001"",
""ruleKey"": ""TST001.002"",
""level"": ""warning"",
""properties"": {
""warningLevel"": 1
}
},
{
""ruleId"": ""TST001"",
""ruleKey"": ""TST001.003"",
""level"": ""warning"",
""properties"": {
""warningLevel"": 1
}
}
],
""rules"": {
""TST001"": {
""id"": ""TST001"",
""shortDescription"": ""_TST001_"",
""defaultLevel"": ""warning"",
//.........这里部分代码省略.........