0
votes

I have multiple ASP .NET MVC and Web Api apps hosted on Azure. I use two differents stages for deployment : stage and PROD. Basically, I want to have two different folders for logs : logs-stage and logs-PROD. This is working well based on my web.config and properties set directly in Azure.

The issue is that each time I deploy, all the previous logs are deleted. How can I avoid that ?

My NLog config looks like the following :

<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
   <targets>
      <target xsi:type="File" name="f" fileName="${basedir}/logs-${appsetting:name=Version:default=DEV}/website.${shortdate}.log"
        layout="${longdate} ${uppercase:${level}} ${logger} - ${message}" />

      <target name="email-Errors" xsi:type="Mail"
             smtpServer="smtp.sendgrid.net"
             smtpPort="myPort"
             enableSsl="false"
             smtpUsername="myUsername"
             smtpPassword="myPassword"
             smtpAuthentication="Basic"
             from="myEmail"
             to="${appsetting:name=WEBSITE_EMAIL_DEVELOPERS:default=myEmail}"
             subject="[${appsetting:name=Version:default=DEV}][WEB][${uppercase:${level}}]"
             layout="${longdate} ${uppercase:${level}} ${logger} - ${message}"
             html="false" />
   </targets>

   <rules>
      <logger name="*" minlevel="Trace" writeTo="f" />
      <logger name="*" minlevel="Error" writeTo="email-Errors" />
   </rules>
</nlog>
1

1 Answers

2
votes

The issue is that each time I deploy, all the previous logs are deleted. How can I avoid that ?

According to your description, it seems that when you publish the WebApp then remove additional file in the Azure WebApp. If it is that case please have a try to uncheck the [Remove additional files as destination] option during publish the WebApp.

enter image description here

Updated:

From the blog, we could know that if we swap the slots, just the DNS pointer changes, so if you have the nlog in the product after swap then the Nlog file is in the staging slot that not deleted. The following the snippet from the blog.

In short, the Swap operation will exchange the website's content between 2 deployment slots.

Swapped and what is not but note that swap is not about copying the content of the website but more about swapping DNS pointers.