2
votes

I am using log4net in my web application We are deploying it via Cloud Services (NOT App Services).

My understanding is that I won't be able to access the log files on disk (and further, these files are not persistent anyways).

My readings are to use Blob storage. But I don't see any code out there on how to do this. There is a nuget package https://www.nuget.org/packages/log4net.Appender.Azure but the documentation says it creates a file for each log entry.

What I want is the RollingLogFile.

Do I basically have to create my own? as in, pull down the log4net source code and create my own appender that logs to a cloud storage account instead of disk? Seems like a lot of work, would have thought someone would have coded this feature already?

Thanks.

1

1 Answers

3
votes

This project shares us some samples that store log entry in Azure Blob storage using AzureBlobAppender or AzureAppendBlobAppender for log4Net.

According the code, we could find AzureBlobAppender will create separate xml file for each log entity in Azure Blob storage, but AzureAppendBlobAppender will store logs that generated in one day in one log file by calling CloudAppendBlob.AppendBlock method to append a new block of logs data to the end of an existing blob.

If you do not want to create a xml file for each log entry, you could try to use AzureAppendBlobAppender.

private static string Filename(string directoryName){
    return string.Format("**{0}/{1}.entry.log.xml**",
                            directoryName,
                            DateTime.Today.ToString("yyyy_MM_dd",
                            DateTimeFormatInfo.InvariantInfo));
}