Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Nlog Posting to a CosmosDB Target

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

like image 977
II Basil II Avatar asked Dec 07 '25 06:12

II Basil II


1 Answers

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"
        });
like image 167
ngruson Avatar answered Dec 09 '25 19:12

ngruson