in src/Core/Compiling/Policy/LogToEventHubCompiler.cs [18:69]
public void Handle(ICompilationContext context, InvocationExpressionSyntax node)
{
if (!node.TryExtractingConfigParameter<LogToEventHubConfig>(context, "log-to-eventhub",
out IReadOnlyDictionary<string, InitializerValue>? values))
{
return;
}
XElement element = new("log-to-eventhub");
if (!element.AddAttribute(values, nameof(LogToEventHubConfig.LoggerId), "logger-id"))
{
context.Report(Diagnostic.Create(
CompilationErrors.RequiredParameterNotDefined,
node.GetLocation(),
"log-to-eventhub",
nameof(LogToEventHubConfig.LoggerId)
));
return;
}
bool addedPartitionKey =
element.AddAttribute(values, nameof(LogToEventHubConfig.PartitionKey), "partition-key");
bool addedPartitionId = element.AddAttribute(values, nameof(LogToEventHubConfig.PartitionId), "partition-id");
if (addedPartitionKey && addedPartitionId)
{
context.Report(Diagnostic.Create(
CompilationErrors.OnlyOneOfTwoShouldBeDefined,
node.GetLocation(),
"log-to-eventhub",
nameof(LogToEventHubConfig.PartitionKey),
nameof(LogToEventHubConfig.PartitionId)
));
return;
}
if (!values.TryGetValue(nameof(LogToEventHubConfig.Value), out InitializerValue? initializerValue) ||
initializerValue.Value is null)
{
context.Report(Diagnostic.Create(
CompilationErrors.RequiredParameterNotDefined,
node.GetLocation(),
"log-to-eventhub",
nameof(LogToEventHubConfig.Value)
));
return;
}
element.Add(initializerValue.Value);
context.AddPolicy(element);
}