JDetmar / NLog.Extensions.AzureStorage

NLog Target for Azure Storage. Uses NLog batch write to optimize writes to Storage.
MIT License
31 stars 19 forks source link

Nlog For Azure File Share #140

Closed ManaiAbdessalem closed 1 year ago

ManaiAbdessalem commented 1 year ago

I am using Nlog in my C# project and i want to save logs in Azure File Share. I found this nuget and its Github "NLog.Extensions.AzureStorage". https://github.com/JDetmar/NLog.Extensions.AzureStorage It contains Targets: AzureAccessToken, AzureBlobStorage, AzureCosmosTable, AzureDataTables, AzureEventGrid, AzureEventHub, AzureQueueStorage, AzureServiceBus.

But there is no target for Azure File Share.

Does anyone know why Azure File Share isn't on the list? Has anyone used nlog in azure file share?

snakefoot commented 1 year ago

Think there is a limitation with Azure File Shares, that file-append-operation is not available. This means one can only create new files, or append to the file by downloading the existing file and append in memory and upload the entire file again. Usually people use Azure Blob Storage instead of Azure File Share: https://github.com/JDetmar/NLog.Extensions.AzureStorage/blob/master/src/NLog.Extensions.AzureBlobStorage/README.md

See also: https://stackoverflow.com/questions/76721836/nlog-in-azure-file-share See also: https://stackoverflow.com/questions/73767453/how-to-integrate-nlog-to-write-log-to-azure-file-share-in-net See also: https://learn.microsoft.com/en-us/rest/api/storageservices/operations-on-files (No append operation)

snakefoot commented 1 year ago

If you are mounting as network-file-share (SMB / NFS), then I guess you can just use NLog FileTarget (KeepFileOpen=false) and assign FileName to the mounted network-drive.

See also: https://learn.microsoft.com/en-us/azure/storage/files/storage-how-to-use-files-windows See also: https://learn.microsoft.com/en-us/azure/storage/files/storage-how-to-use-files-linux

ManaiAbdessalem commented 1 year ago

Thanks for your help. I used File target and i mounted an Azure File Share to AppService directory that contains logs. It works well!