{"id":151,"date":"2019-05-29T19:26:13","date_gmt":"2019-05-29T19:26:13","guid":{"rendered":"http:\/\/yer.ac\/blog\/?p=151"},"modified":"2019-05-29T19:33:04","modified_gmt":"2019-05-29T19:33:04","slug":"remote-nlog-logging-with-azure-functions-part-two-persisting-data-into-azure-cosmos-db","status":"publish","type":"post","link":"https:\/\/yer.ac\/blog\/2019\/05\/29\/remote-nlog-logging-with-azure-functions-part-two-persisting-data-into-azure-cosmos-db\/","title":{"rendered":"Remote NLOG logging with Azure Functions (Part two) &#8211; Persisting data into Azure Cosmos DB."},"content":{"rendered":"\n<p><a href=\"http:\/\/yer.ac\/blog\/2019\/05\/29\/remote-nlog-logging-with-azure-functions-part-one\/\">Last time<\/a>, I got a very basic C# Azure Function hooked up to accept a request from an NLOG web service target.  This time, I will be attempting to persist(insert) the incoming log information into an Azure Cosmos database container, direct from my Azure Function in VS Code.<\/p>\n\n\n\n<p><strong>Disclaimer<\/strong>: This blog is more of a &#8220;mental notes&#8221; for me. I am nowhere near an expert in this area, and Cosmos DB is still new (hours old) to me. Drop me a line if I have missed the point massively \ud83d\ude42<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Setting up Cosmos DB, databases and containers.<\/h2>\n\n\n\n<p>To get started I will make a new Cosmos DB on the Azure Portal by selecting &#8220;Azure Cosmos DB&#8221; from the resources panel and selecting &#8220;Create new&#8221;.<\/p>\n\n\n\n<p>On this page I need to specify:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>Subscription: Your Azure subscription to create this under.<\/li><li>Resource Group: You should already have a resource group which matches the Azure Function you created earlier.<\/li><li>Instance Details<ul><li>Account Name:  This will be prefixed to the URL &#8211; i.e. <strong>blah<\/strong>documents.azure.com<\/li><li>API: For this example I will be using Core(SQL) so I can&nbsp;create a document database and query using SQL syntax.&nbsp; <\/li><\/ul><\/li><li>Location: Select the closest location to you.<\/li><li>Other options: Other options like Geo-Redundancy etc can be left as disabled for now.<\/li><\/ul>\n\n\n\n<p>Select &#8220;Review and Create&#8221;, then on the next screen &#8220;Create&#8221; &#8211; Providing you are happy with the inputs.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img loading=\"lazy\" decoding=\"async\" width=\"1234\" height=\"453\" data-attachment-id=\"153\" data-permalink=\"https:\/\/yer.ac\/blog\/2019\/05\/29\/remote-nlog-logging-with-azure-functions-part-two-persisting-data-into-azure-cosmos-db\/image-12-2\/\" data-orig-file=\"https:\/\/i0.wp.com\/yer.ac\/blog\/wp-content\/uploads\/2019\/05\/image-12.png?fit=1234%2C453&amp;ssl=1\" data-orig-size=\"1234,453\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}\" data-image-title=\"image-12\" data-image-description=\"\" data-image-caption=\"\" data-medium-file=\"https:\/\/i0.wp.com\/yer.ac\/blog\/wp-content\/uploads\/2019\/05\/image-12.png?fit=300%2C110&amp;ssl=1\" data-large-file=\"https:\/\/i0.wp.com\/yer.ac\/blog\/wp-content\/uploads\/2019\/05\/image-12.png?fit=700%2C257&amp;ssl=1\" src=\"https:\/\/i2.wp.com\/yer.ac\/blog\/wp-content\/uploads\/2019\/05\/image-12.png?fit=700%2C257\" alt=\"\" class=\"wp-image-153\" srcset=\"https:\/\/i0.wp.com\/yer.ac\/blog\/wp-content\/uploads\/2019\/05\/image-12.png?w=1234&amp;ssl=1 1234w, https:\/\/i0.wp.com\/yer.ac\/blog\/wp-content\/uploads\/2019\/05\/image-12.png?resize=300%2C110&amp;ssl=1 300w, https:\/\/i0.wp.com\/yer.ac\/blog\/wp-content\/uploads\/2019\/05\/image-12.png?resize=768%2C282&amp;ssl=1 768w, https:\/\/i0.wp.com\/yer.ac\/blog\/wp-content\/uploads\/2019\/05\/image-12.png?resize=700%2C257&amp;ssl=1 700w, https:\/\/i0.wp.com\/yer.ac\/blog\/wp-content\/uploads\/2019\/05\/image-12.png?resize=1200%2C441&amp;ssl=1 1200w\" sizes=\"auto, (max-width: 1000px) 100vw, 1000px\" \/><\/figure>\n\n\n\n<p>Which will switch to &#8220;Your deployment is complete&#8221; when it is ready to be used. It shouldn&#8217;t take longer than a couple of minutes.<\/p>\n\n\n\n<p>Clicking on &#8220;Go to resource&#8221;, or navigating to your new Cosmos DB via the Resource manager will load up the quick-start window for this database. First however, we need a &#8220;container&#8221;. Selecting the Azure Cosmos DB account we just created, we need to select &#8220;Add container&#8221;. <\/p>\n\n\n\n<figure class=\"wp-block-image\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"417\" height=\"577\" data-attachment-id=\"155\" data-permalink=\"https:\/\/yer.ac\/blog\/2019\/05\/29\/remote-nlog-logging-with-azure-functions-part-two-persisting-data-into-azure-cosmos-db\/image-13-2\/\" data-orig-file=\"https:\/\/i0.wp.com\/yer.ac\/blog\/wp-content\/uploads\/2019\/05\/image-13.png?fit=417%2C577&amp;ssl=1\" data-orig-size=\"417,577\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}\" data-image-title=\"image-13\" data-image-description=\"\" data-image-caption=\"\" data-medium-file=\"https:\/\/i0.wp.com\/yer.ac\/blog\/wp-content\/uploads\/2019\/05\/image-13.png?fit=217%2C300&amp;ssl=1\" data-large-file=\"https:\/\/i0.wp.com\/yer.ac\/blog\/wp-content\/uploads\/2019\/05\/image-13.png?fit=417%2C577&amp;ssl=1\" src=\"https:\/\/i0.wp.com\/yer.ac\/blog\/wp-content\/uploads\/2019\/05\/image-13.png?resize=417%2C577\" alt=\"\" class=\"wp-image-155\" srcset=\"https:\/\/i0.wp.com\/yer.ac\/blog\/wp-content\/uploads\/2019\/05\/image-13.png?w=417&amp;ssl=1 417w, https:\/\/i0.wp.com\/yer.ac\/blog\/wp-content\/uploads\/2019\/05\/image-13.png?resize=217%2C300&amp;ssl=1 217w\" sizes=\"auto, (max-width: 417px) 100vw, 417px\" \/><\/figure>\n\n\n\n<p>Here we have a few inputs:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>Database ID. I didn&#8217;t have a database, so needed to create one. If you already have one, specify the name here. <\/li><li>Throughput: 400 RU (Request Units\/S) should be more than enough for basic testing and operation for my purpose.<\/li><li>Container ID: I specified a container ID that lives inside the new\/existing database. <strong>azlogger <\/strong>is where I want all my logging related data, and a container of <strong>azlogger-logs<\/strong> for the logs I will be storing.<\/li><li>Partition key: I used &#8220;loggerName&#8221; as my partition key. See this <a href=\"https:\/\/azure.microsoft.com\/en-us\/resources\/videos\/azure-documentdb-elastic-scale-partitioning\/\">video<\/a> for info, but essentially I believe this is for managing partitions if the data exceeds the limit so partitions can be grouped(?) correctly (~10GB?). <strong>I&#8221;m not 100% sure to be honest, without reading more.<\/strong> I just went with a recommended S\/O post.<\/li><\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">Updating the Azure function to connect with Cosmos DB<\/h2>\n\n\n\n<p>We first need to use the CosmosDB package in this project, so in the terminal, run:<\/p>\n\n\n\n<p><code>dotnet add package Microsoft.Azure.WebJobs.Extensions.CosmosDB<\/code><\/p>\n\n\n\n<p>Now I need to set up the solution so it&#8217;s ready for using Cosmos DB.<\/p>\n\n\n\n<p>In <code>local.settings.json<\/code> I added my connection string:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"> {\n    \"IsEncrypted\": false,\n    \"Values\": {\n        \"AzureWebJobsStorage\": \"\",\n        \"FUNCTIONS_WORKER_RUNTIME\": \"dotnet\",\n        \"MyCosmosDBConnection\": \"&lt;conn string&gt;\"\n    }\n} <\/pre>\n\n\n\n<p>Where the connection string value comes from your Cosmos dashboard, under &#8220;Keys&#8221; -&gt; &#8220;Primary connection string&#8221;<\/p>\n\n\n\n<p>Now I will need a C# model to bind against. I made a simple LogDetail class with the required fields. Note that I am using the JsonProperty items on the fields. I read conflicting blog posts about the requirement for annotating everything other than the ID, but I found no harm in leaving it in for now.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">  public class LogDetail{\n        [JsonProperty(\"id\")]\n        public string Id { get; set; }\n\n        [JsonProperty(\"timestamp\")]\n        public string Timestamp;\n        [JsonProperty(\"logName\")]\n        public string LogName;\n\n        [JsonProperty(\"logLevel\")]\n        public string LogLevel;\n\n        [JsonProperty(\"message\")]\n        public string Message;\n    } <\/pre>\n\n\n\n<p>Now time to update the main method\/function! This was actually the hardest part for me (Partly due to lack of experience with this tech), the documentation was a little confusing, misleading and often specific to a particular scenario.<\/p>\n\n\n\n<p>I&#8217;m not sure how <em>correct <\/em>this is, but I ended up changing my main method so that it read:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">public static class Log\n    {\n        [FunctionName(\"Log\")]\n        public static <strong>void <\/strong>AcceptLogRequest(\n            [HttpTrigger(AuthorizationLevel.Anonymous, \"get\", \"post\", Route = \"Log\")] HttpRequest req,\n            <strong>[CosmosDB(\n                databaseName: \"azlogger\",\n                collectionName: \"azlogger-logs\",\n                ConnectionStringSetting = \"MyCosmosDBConnection\",\n                Id = \"{sys.randguid}\",\n                PartitionKey =\"\/loggerName\"\n                )]\n            out <\/strong>LogDetail logDetail,\n            ILogger log)\n        {\n            log.LogInformation(\"HTTP trigger fired for log entry.\");\n            string timestamp = req.Form[\"timestamp\"]; \n            string loggerName = req.Form[\"loggerName\"]; \n            string loggerLevel = req.Form[\"loggerLevel\"]; \n            string message = req.Form[\"message\"]; \n\n            var res = $\"{timestamp} | {loggerName} | {loggerLevel.ToUpper()} | {message}\";\n            log.LogInformation(res);            \n            logDetail = new LogDetail();\n            logDetail.Timestamp = timestamp;\n            logDetail.LogLevel = loggerLevel;\n            logDetail.LogName = loggerName;\n            logDetail.Message = message; \n        }\n    }<\/pre>\n\n\n\n<p>The main changes were:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>Making it a synchronous  void method for saving data into CosmosDb which was recommended in the Microsoft Docs <a href=\"https:\/\/docs.microsoft.com\/en-us\/azure\/azure-functions\/functions-bindings-cosmosdb-v2\">here<\/a>. Could be wrong, but it works and is in-line with their docs.<\/li><li>changing <code>LogDetail logdetail<\/code> to be <code>out LogDetail logDetail<\/code><\/li><li>Add in the Cosmos DB annotation (See below)<\/li><\/ul>\n\n\n\n<p>The CosmosDB annotation has the following options:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li><strong>databaseName<\/strong>: This is the main database name for the database set up in the previous step.<\/li><li><strong>collectionName<\/strong>: This is the <em><strong>container <\/strong><\/em>name set up in the previous step<\/li><li><strong>ConnectionStringSetting<\/strong>: The app setting name placed inside <code>local.settings.json<\/code> in the previous step.<\/li><li><strong>id<\/strong>: The Id entry for the record. For this I used an inbuilt system parameter of <strong><code>{sys.randguid}<\/code><\/strong><\/li><li><strong>partitionKey<\/strong>: The partition key I specified in the earlier setup step.<\/li><\/ul>\n\n\n\n<p>Now, if I debug (or deploy) this Azure Function and cause my application to insert a bunch of NLOG entries, it should now create some entries in a Cosmos DB container.<\/p>\n\n\n\n<p>To view the results, I can go to Cosmos DB on the Azure portal and select  &#8220;Data Explorer&#8221;. From here, the Database and Container can be expanded to show the &#8220;Items&#8221; in the container &#8211; In my case, a load of NLOG entries.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img loading=\"lazy\" decoding=\"async\" width=\"1338\" height=\"660\" data-attachment-id=\"163\" data-permalink=\"https:\/\/yer.ac\/blog\/2019\/05\/29\/remote-nlog-logging-with-azure-functions-part-two-persisting-data-into-azure-cosmos-db\/image-15-2\/\" data-orig-file=\"https:\/\/i0.wp.com\/yer.ac\/blog\/wp-content\/uploads\/2019\/05\/image-15.png?fit=1338%2C660&amp;ssl=1\" data-orig-size=\"1338,660\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}\" data-image-title=\"image-15\" data-image-description=\"\" data-image-caption=\"\" data-medium-file=\"https:\/\/i0.wp.com\/yer.ac\/blog\/wp-content\/uploads\/2019\/05\/image-15.png?fit=300%2C148&amp;ssl=1\" data-large-file=\"https:\/\/i0.wp.com\/yer.ac\/blog\/wp-content\/uploads\/2019\/05\/image-15.png?fit=700%2C345&amp;ssl=1\" src=\"https:\/\/i1.wp.com\/yer.ac\/blog\/wp-content\/uploads\/2019\/05\/image-15.png?fit=700%2C345\" alt=\"\" class=\"wp-image-163\" srcset=\"https:\/\/i0.wp.com\/yer.ac\/blog\/wp-content\/uploads\/2019\/05\/image-15.png?w=1338&amp;ssl=1 1338w, https:\/\/i0.wp.com\/yer.ac\/blog\/wp-content\/uploads\/2019\/05\/image-15.png?resize=300%2C148&amp;ssl=1 300w, https:\/\/i0.wp.com\/yer.ac\/blog\/wp-content\/uploads\/2019\/05\/image-15.png?resize=768%2C379&amp;ssl=1 768w, https:\/\/i0.wp.com\/yer.ac\/blog\/wp-content\/uploads\/2019\/05\/image-15.png?resize=700%2C345&amp;ssl=1 700w, https:\/\/i0.wp.com\/yer.ac\/blog\/wp-content\/uploads\/2019\/05\/image-15.png?resize=1200%2C592&amp;ssl=1 1200w\" sizes=\"auto, (max-width: 1000px) 100vw, 1000px\" \/><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">Conclusion<\/h2>\n\n\n\n<p>It&#8217;s early days, but deploying a new Azure function is trivially easy using the most recent tooling, and the only real difficulty seems to be nailing down decent documentation in Azure (Which has always been the case from my experience!)<\/p>\n\n\n\n<p>The next stages would be to look into Azure Function triggers on a timer to produce MI reports, or time\/action based triggers to forward captured events onto the appropriate person. <\/p>\n","protected":false},"excerpt":{"rendered":"<p>Last time, I got a very basic C# Azure Function hooked up to accept a request from an NLOG web service target. This time, I will be attempting to persist(insert) the incoming log information into an Azure Cosmos database container, direct from my Azure Function in VS Code. Disclaimer: This blog is more of a &hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[19],"tags":[20,21,23],"class_list":["post-151","post","type-post","status-publish","format-standard","hentry","category-azure","tag-azure","tag-azure-functions","tag-cosmos-db"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.3 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Remote NLOG logging with Azure Functions (Part two) - Persisting data into Azure Cosmos DB. - yer.ac | Adventures of a developer, and other things.<\/title>\n<meta name=\"description\" content=\"Persisting data into Cosmos DB from a C# Azure Function in VS Code.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/yer.ac\/blog\/2019\/05\/29\/remote-nlog-logging-with-azure-functions-part-two-persisting-data-into-azure-cosmos-db\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Remote NLOG logging with Azure Functions (Part two) - Persisting data into Azure Cosmos DB. - yer.ac | Adventures of a developer, and other things.\" \/>\n<meta property=\"og:description\" content=\"Persisting data into Cosmos DB from a C# Azure Function in VS Code.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/yer.ac\/blog\/2019\/05\/29\/remote-nlog-logging-with-azure-functions-part-two-persisting-data-into-azure-cosmos-db\/\" \/>\n<meta property=\"og:site_name\" content=\"yer.ac | Adventures of a developer, and other things.\" \/>\n<meta property=\"article:published_time\" content=\"2019-05-29T19:26:13+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2019-05-29T19:33:04+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/i2.wp.com\/yer.ac\/blog\/wp-content\/uploads\/2019\/05\/image-12.png?fit=700%2C257\" \/>\n<meta name=\"author\" content=\"yer.ac\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"yer.ac\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"5 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/yer.ac\\\/blog\\\/2019\\\/05\\\/29\\\/remote-nlog-logging-with-azure-functions-part-two-persisting-data-into-azure-cosmos-db\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/yer.ac\\\/blog\\\/2019\\\/05\\\/29\\\/remote-nlog-logging-with-azure-functions-part-two-persisting-data-into-azure-cosmos-db\\\/\"},\"author\":{\"name\":\"yer.ac\",\"@id\":\"https:\\\/\\\/yer.ac\\\/blog\\\/#\\\/schema\\\/person\\\/4638b9d868c7d3747bd3bb01fbc8153d\"},\"headline\":\"Remote NLOG logging with Azure Functions (Part two) &#8211; Persisting data into Azure Cosmos DB.\",\"datePublished\":\"2019-05-29T19:26:13+00:00\",\"dateModified\":\"2019-05-29T19:33:04+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/yer.ac\\\/blog\\\/2019\\\/05\\\/29\\\/remote-nlog-logging-with-azure-functions-part-two-persisting-data-into-azure-cosmos-db\\\/\"},\"wordCount\":905,\"commentCount\":1,\"publisher\":{\"@id\":\"https:\\\/\\\/yer.ac\\\/blog\\\/#\\\/schema\\\/person\\\/4638b9d868c7d3747bd3bb01fbc8153d\"},\"image\":{\"@id\":\"https:\\\/\\\/yer.ac\\\/blog\\\/2019\\\/05\\\/29\\\/remote-nlog-logging-with-azure-functions-part-two-persisting-data-into-azure-cosmos-db\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/i2.wp.com\\\/yer.ac\\\/blog\\\/wp-content\\\/uploads\\\/2019\\\/05\\\/image-12.png?fit=700%2C257\",\"keywords\":[\"Azure\",\"Azure Functions\",\"Cosmos DB\"],\"articleSection\":[\"Azure\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/yer.ac\\\/blog\\\/2019\\\/05\\\/29\\\/remote-nlog-logging-with-azure-functions-part-two-persisting-data-into-azure-cosmos-db\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/yer.ac\\\/blog\\\/2019\\\/05\\\/29\\\/remote-nlog-logging-with-azure-functions-part-two-persisting-data-into-azure-cosmos-db\\\/\",\"url\":\"https:\\\/\\\/yer.ac\\\/blog\\\/2019\\\/05\\\/29\\\/remote-nlog-logging-with-azure-functions-part-two-persisting-data-into-azure-cosmos-db\\\/\",\"name\":\"Remote NLOG logging with Azure Functions (Part two) - Persisting data into Azure Cosmos DB. - yer.ac | Adventures of a developer, and other things.\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/yer.ac\\\/blog\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/yer.ac\\\/blog\\\/2019\\\/05\\\/29\\\/remote-nlog-logging-with-azure-functions-part-two-persisting-data-into-azure-cosmos-db\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/yer.ac\\\/blog\\\/2019\\\/05\\\/29\\\/remote-nlog-logging-with-azure-functions-part-two-persisting-data-into-azure-cosmos-db\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/i2.wp.com\\\/yer.ac\\\/blog\\\/wp-content\\\/uploads\\\/2019\\\/05\\\/image-12.png?fit=700%2C257\",\"datePublished\":\"2019-05-29T19:26:13+00:00\",\"dateModified\":\"2019-05-29T19:33:04+00:00\",\"description\":\"Persisting data into Cosmos DB from a C# Azure Function in VS Code.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/yer.ac\\\/blog\\\/2019\\\/05\\\/29\\\/remote-nlog-logging-with-azure-functions-part-two-persisting-data-into-azure-cosmos-db\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/yer.ac\\\/blog\\\/2019\\\/05\\\/29\\\/remote-nlog-logging-with-azure-functions-part-two-persisting-data-into-azure-cosmos-db\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/yer.ac\\\/blog\\\/2019\\\/05\\\/29\\\/remote-nlog-logging-with-azure-functions-part-two-persisting-data-into-azure-cosmos-db\\\/#primaryimage\",\"url\":\"https:\\\/\\\/i2.wp.com\\\/yer.ac\\\/blog\\\/wp-content\\\/uploads\\\/2019\\\/05\\\/image-12.png?fit=700%2C257\",\"contentUrl\":\"https:\\\/\\\/i2.wp.com\\\/yer.ac\\\/blog\\\/wp-content\\\/uploads\\\/2019\\\/05\\\/image-12.png?fit=700%2C257\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/yer.ac\\\/blog\\\/2019\\\/05\\\/29\\\/remote-nlog-logging-with-azure-functions-part-two-persisting-data-into-azure-cosmos-db\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/yer.ac\\\/blog\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Remote NLOG logging with Azure Functions (Part two) &#8211; Persisting data into Azure Cosmos DB.\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/yer.ac\\\/blog\\\/#website\",\"url\":\"https:\\\/\\\/yer.ac\\\/blog\\\/\",\"name\":\"yer.ac | Adventures of a developer, and other things.\",\"description\":\"Blog to keep track of things I am upto\",\"publisher\":{\"@id\":\"https:\\\/\\\/yer.ac\\\/blog\\\/#\\\/schema\\\/person\\\/4638b9d868c7d3747bd3bb01fbc8153d\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/yer.ac\\\/blog\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":[\"Person\",\"Organization\"],\"@id\":\"https:\\\/\\\/yer.ac\\\/blog\\\/#\\\/schema\\\/person\\\/4638b9d868c7d3747bd3bb01fbc8153d\",\"name\":\"yer.ac\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/67ed010c9cc7986d40647e061c6dcdb06d818776591c7e954055adb629621113?s=96&d=retro&r=pg\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/67ed010c9cc7986d40647e061c6dcdb06d818776591c7e954055adb629621113?s=96&d=retro&r=pg\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/67ed010c9cc7986d40647e061c6dcdb06d818776591c7e954055adb629621113?s=96&d=retro&r=pg\",\"caption\":\"yer.ac\"},\"logo\":{\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/67ed010c9cc7986d40647e061c6dcdb06d818776591c7e954055adb629621113?s=96&d=retro&r=pg\"}}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Remote NLOG logging with Azure Functions (Part two) - Persisting data into Azure Cosmos DB. - yer.ac | Adventures of a developer, and other things.","description":"Persisting data into Cosmos DB from a C# Azure Function in VS Code.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/yer.ac\/blog\/2019\/05\/29\/remote-nlog-logging-with-azure-functions-part-two-persisting-data-into-azure-cosmos-db\/","og_locale":"en_US","og_type":"article","og_title":"Remote NLOG logging with Azure Functions (Part two) - Persisting data into Azure Cosmos DB. - yer.ac | Adventures of a developer, and other things.","og_description":"Persisting data into Cosmos DB from a C# Azure Function in VS Code.","og_url":"https:\/\/yer.ac\/blog\/2019\/05\/29\/remote-nlog-logging-with-azure-functions-part-two-persisting-data-into-azure-cosmos-db\/","og_site_name":"yer.ac | Adventures of a developer, and other things.","article_published_time":"2019-05-29T19:26:13+00:00","article_modified_time":"2019-05-29T19:33:04+00:00","og_image":[{"url":"https:\/\/i2.wp.com\/yer.ac\/blog\/wp-content\/uploads\/2019\/05\/image-12.png?fit=700%2C257","type":"","width":"","height":""}],"author":"yer.ac","twitter_card":"summary_large_image","twitter_misc":{"Written by":"yer.ac","Est. reading time":"5 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/yer.ac\/blog\/2019\/05\/29\/remote-nlog-logging-with-azure-functions-part-two-persisting-data-into-azure-cosmos-db\/#article","isPartOf":{"@id":"https:\/\/yer.ac\/blog\/2019\/05\/29\/remote-nlog-logging-with-azure-functions-part-two-persisting-data-into-azure-cosmos-db\/"},"author":{"name":"yer.ac","@id":"https:\/\/yer.ac\/blog\/#\/schema\/person\/4638b9d868c7d3747bd3bb01fbc8153d"},"headline":"Remote NLOG logging with Azure Functions (Part two) &#8211; Persisting data into Azure Cosmos DB.","datePublished":"2019-05-29T19:26:13+00:00","dateModified":"2019-05-29T19:33:04+00:00","mainEntityOfPage":{"@id":"https:\/\/yer.ac\/blog\/2019\/05\/29\/remote-nlog-logging-with-azure-functions-part-two-persisting-data-into-azure-cosmos-db\/"},"wordCount":905,"commentCount":1,"publisher":{"@id":"https:\/\/yer.ac\/blog\/#\/schema\/person\/4638b9d868c7d3747bd3bb01fbc8153d"},"image":{"@id":"https:\/\/yer.ac\/blog\/2019\/05\/29\/remote-nlog-logging-with-azure-functions-part-two-persisting-data-into-azure-cosmos-db\/#primaryimage"},"thumbnailUrl":"https:\/\/i2.wp.com\/yer.ac\/blog\/wp-content\/uploads\/2019\/05\/image-12.png?fit=700%2C257","keywords":["Azure","Azure Functions","Cosmos DB"],"articleSection":["Azure"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/yer.ac\/blog\/2019\/05\/29\/remote-nlog-logging-with-azure-functions-part-two-persisting-data-into-azure-cosmos-db\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/yer.ac\/blog\/2019\/05\/29\/remote-nlog-logging-with-azure-functions-part-two-persisting-data-into-azure-cosmos-db\/","url":"https:\/\/yer.ac\/blog\/2019\/05\/29\/remote-nlog-logging-with-azure-functions-part-two-persisting-data-into-azure-cosmos-db\/","name":"Remote NLOG logging with Azure Functions (Part two) - Persisting data into Azure Cosmos DB. - yer.ac | Adventures of a developer, and other things.","isPartOf":{"@id":"https:\/\/yer.ac\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/yer.ac\/blog\/2019\/05\/29\/remote-nlog-logging-with-azure-functions-part-two-persisting-data-into-azure-cosmos-db\/#primaryimage"},"image":{"@id":"https:\/\/yer.ac\/blog\/2019\/05\/29\/remote-nlog-logging-with-azure-functions-part-two-persisting-data-into-azure-cosmos-db\/#primaryimage"},"thumbnailUrl":"https:\/\/i2.wp.com\/yer.ac\/blog\/wp-content\/uploads\/2019\/05\/image-12.png?fit=700%2C257","datePublished":"2019-05-29T19:26:13+00:00","dateModified":"2019-05-29T19:33:04+00:00","description":"Persisting data into Cosmos DB from a C# Azure Function in VS Code.","breadcrumb":{"@id":"https:\/\/yer.ac\/blog\/2019\/05\/29\/remote-nlog-logging-with-azure-functions-part-two-persisting-data-into-azure-cosmos-db\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/yer.ac\/blog\/2019\/05\/29\/remote-nlog-logging-with-azure-functions-part-two-persisting-data-into-azure-cosmos-db\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/yer.ac\/blog\/2019\/05\/29\/remote-nlog-logging-with-azure-functions-part-two-persisting-data-into-azure-cosmos-db\/#primaryimage","url":"https:\/\/i2.wp.com\/yer.ac\/blog\/wp-content\/uploads\/2019\/05\/image-12.png?fit=700%2C257","contentUrl":"https:\/\/i2.wp.com\/yer.ac\/blog\/wp-content\/uploads\/2019\/05\/image-12.png?fit=700%2C257"},{"@type":"BreadcrumbList","@id":"https:\/\/yer.ac\/blog\/2019\/05\/29\/remote-nlog-logging-with-azure-functions-part-two-persisting-data-into-azure-cosmos-db\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/yer.ac\/blog\/"},{"@type":"ListItem","position":2,"name":"Remote NLOG logging with Azure Functions (Part two) &#8211; Persisting data into Azure Cosmos DB."}]},{"@type":"WebSite","@id":"https:\/\/yer.ac\/blog\/#website","url":"https:\/\/yer.ac\/blog\/","name":"yer.ac | Adventures of a developer, and other things.","description":"Blog to keep track of things I am upto","publisher":{"@id":"https:\/\/yer.ac\/blog\/#\/schema\/person\/4638b9d868c7d3747bd3bb01fbc8153d"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/yer.ac\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":["Person","Organization"],"@id":"https:\/\/yer.ac\/blog\/#\/schema\/person\/4638b9d868c7d3747bd3bb01fbc8153d","name":"yer.ac","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/67ed010c9cc7986d40647e061c6dcdb06d818776591c7e954055adb629621113?s=96&d=retro&r=pg","url":"https:\/\/secure.gravatar.com\/avatar\/67ed010c9cc7986d40647e061c6dcdb06d818776591c7e954055adb629621113?s=96&d=retro&r=pg","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/67ed010c9cc7986d40647e061c6dcdb06d818776591c7e954055adb629621113?s=96&d=retro&r=pg","caption":"yer.ac"},"logo":{"@id":"https:\/\/secure.gravatar.com\/avatar\/67ed010c9cc7986d40647e061c6dcdb06d818776591c7e954055adb629621113?s=96&d=retro&r=pg"}}]}},"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/paP5IW-2r","jetpack-related-posts":[{"id":112,"url":"https:\/\/yer.ac\/blog\/2019\/05\/29\/remote-nlog-logging-with-azure-functions-part-one\/","url_meta":{"origin":151,"position":0},"title":"Remote NLOG logging with Azure Functions (Part one).","author":"yer.ac","date":"May 29, 2019","format":false,"excerpt":"Part of a journey I was on today to learn about Azure Functions and Cosmos DB. The final code for the Azure Functions element can be found on https:\/\/github.com\/Wabbbit\/AzLog Part one: Setup, Creating my first function, forwarding NLOG events and deploying to Azure within VS Code.Part two: persisting the incoming\u2026","rel":"","context":"In &quot;Azure&quot;","block_context":{"text":"Azure","link":"https:\/\/yer.ac\/blog\/category\/development\/azure\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/yer.ac\/blog\/wp-content\/uploads\/2019\/05\/image-4.png?resize=350%2C200&ssl=1","width":350,"height":200},"classes":[]},{"id":521,"url":"https:\/\/yer.ac\/blog\/2021\/10\/06\/vs2019-2022-keeps-asking-for-azure-devops-credentials-on-build\/","url_meta":{"origin":151,"position":1},"title":"VS2019 (+2022) keeps asking for Azure Devops Credentials on build","author":"yer.ac","date":"October 6, 2021","format":false,"excerpt":"We run our own nuget feed via Azure, and despite the user that's logged into VS is authenticated users are constantly asked to provide their credentials again when package restore is happening. A quick fix below - Mostly so I don't forget or can forward this to others later. Verify\u2026","rel":"","context":"In &quot;Azure&quot;","block_context":{"text":"Azure","link":"https:\/\/yer.ac\/blog\/category\/development\/azure\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/yer.ac\/blog\/wp-content\/uploads\/2021\/10\/image-1.png?resize=350%2C200&ssl=1","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/yer.ac\/blog\/wp-content\/uploads\/2021\/10\/image-1.png?resize=350%2C200&ssl=1 1x, https:\/\/i0.wp.com\/yer.ac\/blog\/wp-content\/uploads\/2021\/10\/image-1.png?resize=525%2C300&ssl=1 1.5x, https:\/\/i0.wp.com\/yer.ac\/blog\/wp-content\/uploads\/2021\/10\/image-1.png?resize=700%2C400&ssl=1 2x"},"classes":[]},{"id":285,"url":"https:\/\/yer.ac\/blog\/2019\/07\/31\/setting-up-a-self-hosted-build-agent-for-azure-devops\/","url_meta":{"origin":151,"position":2},"title":"Setting up a self-hosted build agent for Azure DevOps","author":"yer.ac","date":"July 31, 2019","format":false,"excerpt":"Azure DevOps has brilliant build pipeline options and as easy as it is to get set up with their hosted build agents, it can get quite costly rather quick. In this post I cover off setting up a self-hosted build agent for use with Azure. This post won't cover setting\u2026","rel":"","context":"In &quot;Azure&quot;","block_context":{"text":"Azure","link":"https:\/\/yer.ac\/blog\/category\/development\/azure\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/yer.ac\/blog\/wp-content\/uploads\/2019\/07\/image.png?resize=350%2C200&ssl=1","width":350,"height":200},"classes":[]},{"id":436,"url":"https:\/\/yer.ac\/blog\/2021\/03\/10\/moving-local-workspaces-between-users-vs2019-tfs-self-hosted-azure-devops\/","url_meta":{"origin":151,"position":3},"title":"Moving local workspaces between users VS2019\/TFS [Self Hosted\/ Azure Devops]","author":"yer.ac","date":"March 10, 2021","format":false,"excerpt":"Whilst I use GIT for most my source control these days, I still have some projects in TFSVC. On a recent switch of Visual Studio accounts I temporarily lost access to my mapped workspaces as these are linked to the VS logged in user, rather than to the machine. This\u2026","rel":"","context":"In &quot;DevOps&quot;","block_context":{"text":"DevOps","link":"https:\/\/yer.ac\/blog\/category\/devops\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/yer.ac\/blog\/wp-content\/uploads\/2021\/03\/image-5.png?resize=350%2C200&ssl=1","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/yer.ac\/blog\/wp-content\/uploads\/2021\/03\/image-5.png?resize=350%2C200&ssl=1 1x, https:\/\/i0.wp.com\/yer.ac\/blog\/wp-content\/uploads\/2021\/03\/image-5.png?resize=525%2C300&ssl=1 1.5x"},"classes":[]},{"id":315,"url":"https:\/\/yer.ac\/blog\/2019\/10\/16\/ensuring-dotnet-test-trx-coverage-files-end-up-in-sonarqube\/","url_meta":{"origin":151,"position":4},"title":"Ensuring &#8220;dotnet test&#8221; TRX &#038; Coverage files end up in SonarQube","author":"yer.ac","date":"October 16, 2019","format":false,"excerpt":"I have written before about using SonarQube to do static analysis, but one issue I never came back to was ensuring that code coverage files generated via a build pipeline end up being picked up by the Sonar Scanner to assess code coverage. Note that the following I am actually\u2026","rel":"","context":"In &quot;DevOps&quot;","block_context":{"text":"DevOps","link":"https:\/\/yer.ac\/blog\/category\/devops\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/yer.ac\/blog\/wp-content\/uploads\/2019\/10\/image.png?resize=350%2C200&ssl=1","width":350,"height":200},"classes":[]},{"id":351,"url":"https:\/\/yer.ac\/blog\/2020\/01\/06\/using-docker-containers-for-easy-local-wordpress-development%f0%9f%90%b3\/","url_meta":{"origin":151,"position":5},"title":"Using Docker Containers for easy local WordPress development\ud83d\udc33","author":"yer.ac","date":"January 6, 2020","format":false,"excerpt":"Creating WordPress development environment using Docker containers.","rel":"","context":"In &quot;Development&quot;","block_context":{"text":"Development","link":"https:\/\/yer.ac\/blog\/category\/development\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/yer.ac\/blog\/wp-content\/uploads\/2020\/01\/image-1.png?fit=648%2C465&ssl=1&resize=350%2C200","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/yer.ac\/blog\/wp-content\/uploads\/2020\/01\/image-1.png?fit=648%2C465&ssl=1&resize=350%2C200 1x, https:\/\/i0.wp.com\/yer.ac\/blog\/wp-content\/uploads\/2020\/01\/image-1.png?fit=648%2C465&ssl=1&resize=525%2C300 1.5x"},"classes":[]}],"_links":{"self":[{"href":"https:\/\/yer.ac\/blog\/wp-json\/wp\/v2\/posts\/151","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/yer.ac\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/yer.ac\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/yer.ac\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/yer.ac\/blog\/wp-json\/wp\/v2\/comments?post=151"}],"version-history":[{"count":18,"href":"https:\/\/yer.ac\/blog\/wp-json\/wp\/v2\/posts\/151\/revisions"}],"predecessor-version":[{"id":176,"href":"https:\/\/yer.ac\/blog\/wp-json\/wp\/v2\/posts\/151\/revisions\/176"}],"wp:attachment":[{"href":"https:\/\/yer.ac\/blog\/wp-json\/wp\/v2\/media?parent=151"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/yer.ac\/blog\/wp-json\/wp\/v2\/categories?post=151"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/yer.ac\/blog\/wp-json\/wp\/v2\/tags?post=151"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}