I'm using Nlog and trying to make it post to a CosmosDB(DocumentDB) target using https://www.nuget.org/packages/Nlog.DocumentDBTarget/
my configuration code looks like this
var documentDBTarget = new DocumentDBTarget()
{
Name = "logDocument",
EndPoint = "https://[my endpoint].documents.azure.com:443/",
AuthorizationKey = "[my auth key]",
Collection = "[my collection]",
Database = "[my database]",
Layout=jsonLayout
};
config.AddTarget(documentDBTarget);
config.AddRuleForAllLevels(documentDBTarget);
I have declared jsonLayout and then I configure the logger and use it to start logging. this was working fine when I was logging to a local file target or a console target but it's not working with cosmosDB
LogManager.Configuration =config;
Logger logger = LogManager.GetLogger("Example");
logger.Info("{object}");
what am I missing? the documentation for https://github.com/goto10hq/NLog.DocumentDB?files=1 I didn't find any information about posting using Nlog I only found info about configuring it which I believe I did correctly
Thank you
Works on my computer. Is the object that you are trying to log consistent with the JSON layout?
var jsonLayout = new JsonLayout()
{
Attributes =
{
new JsonAttribute("name", "${name}"),
new JsonAttribute("level", "${level}"),
new JsonAttribute("message", "${message}"),
}
};
…
logger.Info(new
{
Name = "SomeName",
Level = "SomeLevel",
Message = "HelloWorld"
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With