azureloggingsitecorelog4netlogfile

Logging one file for each day in Azure


This is related to Sitecore logging using log4net in Azure.

Current Behavior:

  1. Multiple files getting created for the day.
  2. The last file of the day is always of a different format(I have tried date tag to resolve..still its not working as expected)

Below are the three screenshots:

The log4net related setting just for azure enter image description here

The only change which I have added at the moment. enter image description here

Multiple files created for 20 Oct(i.e today) and last night file with weird name. enter image description here

Expected behavior: I want to log one file for each day irrespective of the number of restarts/application pool recycle with the date in the name of the file.

  1. Just one file with date in the name included (eg.azure.log.20221020.084617.txt)

Solution

  • An update please, this error got resolved after I used the below code to resolve:

    <appender name="AzureFallbackAppender">
                <rollingStyle>
                    <patch:attribute name="value">Date</patch:attribute>
                </rollingStyle>
                <maximumFileSize>
                    <patch:attribute name="value">50MB</patch:attribute>
                </maximumFileSize>
                <staticLogFileName>
                    <patch:attribute name="value">false</patch:attribute>
                </staticLogFileName>
                <preserveLogFileNameExtension>
                    <patch:attribute name="value">true</patch:attribute>
                </preserveLogFileNameExtension>
                <file>
                    <patch:attribute name="value">D:\home\site\wwwroot\App_Data/logs/{machineName}/azure.log.{date}.{time}.txt</patch:attribute>
                </file>
                <appendToFile>
                    <patch:attribute name="value">true</patch:attribute>
                </appendToFile>
                <layout type="log4net.Layout.PatternLayout">
                    <conversionPattern>
                        <patch:attribute name="value">%4t %d - %-5p %m%n%n%n</patch:attribute>
                    </conversionPattern>
                </layout>
            </appender>