mahdighorbanpour / serilog-sinks-azurecosmosdb

A Serilog sink that writes to Azure CosmosDB and supports PartitionKey for better performance.
Apache License 2.0
4 stars 5 forks source link

Pushing a property to the root of log event object #9

Open cohenjw opened 2 years ago

cohenjw commented 2 years ago

I'm having an issue figuring out if it's possible to pull a property of of the Properties object and push it into the root of the object, in effort to set this property as my partition key.

I would like this because EF Core currently doesn't support the nested partition key (https://github.com/dotnet/efcore/issues/26978)

{ "Properties": { "CorrelationId": "d26b41bd-d107-4f29-955a-68ea5c572f45" }, "UtcDate": "01.07.2022" } (snipped down for brevity)

Where UtcDate is the current partition key, by default. I would like to bring CorrelationId out of the properties object, and into the root so that I can tell EF Core that CorrelationId is the new partition key. I cannot find anything in the Serilog or Cosmos sink docs that may allow me to do this.

Thank you!

tghamm commented 2 years ago

@cohenjw I THINK what you're asking is possible. It's possible to specify CorrelationId as the name/value pair you're looking for during insert using this sink. Basically you'd use your own IPartitionKeyProvider and specify the name of the partitionKey as CorrelationId.

Check out something similar implemented in my fork:

https://github.com/tghamm/serilog-sinks-azcosmosdb/blob/065fcbe5e37b390a766662f5377784e9466556e1/Serilog.Sinks.AzCosmosDB.TestRunner/PartitionKeyProvider.cs#L1-L17