in src/Serilog.Sinks.AzureDataExplorer/Extensions/AzureDataExplorerSinkExtensions.cs [62:181]
public static LoggerConfiguration AzureDataExplorerSink(
this LoggerSinkConfiguration loggerConfiguration,
string ingestionUri,
string databaseName,
string tableName,
string applicationClientId,
string applicationSecret,
string tenantId,
string userToken = null,
bool isManagedIdentity = false,
bool isWorkloadIdentity = false,
bool flushImmediately = true,
string mappingName = null,
string bufferBaseFileName = null,
int bufferFileCountLimit = 20,
long bufferFileSizeLimitBytes = 10L * 1024 * 1024,
string bufferFileOutputFormat =
"{Timestamp:yyyy-MM-dd HH:mm:ss.fff zzz} [{Level:u3}] {Message:lj}{NewLine}{Exception}",
bool useStreamingIngestion = false,
int batchPostingLimit = 1000,
double period = 10,
int queueSizeLimit = 100000,
LogEventLevel restrictedToMinimumLevel = LevelAlias.Minimum)
{
if (loggerConfiguration == null)
{
throw new ArgumentNullException(nameof(loggerConfiguration));
}
if (ingestionUri == null)
{
throw new ArgumentNullException(nameof(ingestionUri));
}
if (databaseName == null)
{
throw new ArgumentNullException(nameof(databaseName));
}
if (tableName == null)
{
throw new ArgumentNullException(nameof(tableName));
}
if (applicationClientId == null)
{
throw new ArgumentNullException(nameof(applicationClientId));
}
if (applicationSecret == null)
{
throw new ArgumentNullException(nameof(applicationSecret));
}
if (tenantId == null)
{
throw new ArgumentNullException(nameof(tenantId));
}
AzureDataExplorerSinkOptions options = new AzureDataExplorerSinkOptions()
{
IngestionEndpointUri = ingestionUri,
DatabaseName = databaseName,
TableName = tableName,
BufferBaseFileName = bufferBaseFileName,
FlushImmediately = flushImmediately,
MappingName = mappingName,
UseStreamingIngestion = useStreamingIngestion,
BufferFileCountLimit = bufferFileCountLimit,
BufferFileSizeLimitBytes = bufferFileSizeLimitBytes,
BufferFileOutputFormat = bufferFileOutputFormat,
BatchPostingLimit = batchPostingLimit,
Period = TimeSpan.FromSeconds(period),
QueueSizeLimit = queueSizeLimit,
};
if (isManagedIdentity)
{
if (string.Equals(applicationClientId, "system", StringComparison.OrdinalIgnoreCase))
{
options = options.WithAadSystemAssignedManagedIdentity();
}
else
{
options = options.WithAadUserAssignedManagedIdentity(applicationClientId);
}
}
else if (isWorkloadIdentity)
{
options = options.WithWorkloadIdentity();
}
else if (!string.IsNullOrEmpty(userToken))
{
options = options.WithAadUserToken(userToken: userToken);
}
else
{
options = options.WithAadApplicationKey(applicationClientId: applicationClientId, applicationKey: applicationSecret, authority: tenantId);
}
var batchingOptions = new BatchingOptions
{
BatchSizeLimit = options.BatchPostingLimit,
BufferingTimeLimit = options.Period,
EagerlyEmitFirstEvent = true,
QueueLimit = options.QueueSizeLimit
};
var azureDataExplorerSink = new AzureDataExplorerSink(options);
var sink = string.IsNullOrWhiteSpace(bufferBaseFileName) ? azureDataExplorerSink : (IBatchedLogEventSink) new AzureDataExplorerDurableSink(options);
return loggerConfiguration.Sink(sink, batchingOptions,
restrictedToMinimumLevel,
options.BufferFileLoggingLevelSwitch);
}