0

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?

I NLog web site https://nlog-project.org/config/, to use Azure file share, they recommand a nuget that is depreceated. I also tried this nuget and does not work.

has anyone used nlog in azure file share?

  • Azure File Share is mounted as a normal Windows "network drive letter": so **you don't need any special libraries**: any logging system that accepts a directory path as a target will work. – Dai Jul 19 '23 at 13:44
  • Duplicate question - https://stackoverflow.com/q/73767453/193178 ? – Rolf Kristensen Jul 19 '23 at 16:26
  • See also: https://github.com/JDetmar/NLog.Extensions.AzureStorage/issues/140 – Rolf Kristensen Jul 19 '23 at 16:27
  • 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 – Rolf Kristensen Jul 19 '23 at 16:28
  • @RolfKristensen _"that file-append-operation is not available"_ - Do you have a source for that? There's no mention of being unable to append to files in Azure Files' "Limitations" documentation: https://learn.microsoft.com/en-us/azure/storage/files/files-smb-protocol?tabs=azure-portal#limitations - and because appending to an existing file is such a very fundamental operation I'd be very surprised if MS launched Azure Files with such a gaping limitation, so I hope you'll forgive my skepticism. – Dai Jul 19 '23 at 17:42
  • @Dai I'm guessing "append" is a trivial atomic-operation when on a local-machine with a single-process. But maybe less trivial in the cloud. See also available operations here: https://learn.microsoft.com/en-us/connectors/azurefile/#actions – Rolf Kristensen Jul 19 '23 at 18:30
  • @RolfKristensen _"is a trivial atomic-operation when on a local-machine with a single-process"_ - With respect, may I ask what your level of experience is with storage technology and theory? You know how NFS and SANs, HBAs, etc work? (Also, there's no mention of "append" on that page about the Azure File Connector (which is an add-in for PowerBI, it's not about the Azure Files service itself), and none of the limitations listed there seem relevant) – Dai Jul 19 '23 at 18:41
  • @Dai Sorry to have offended you. But you are wellcome to create a pull-request to add support for Azure File Share. It is just a fork away - https://github.com/JDetmar/NLog.Extensions.AzureStorage/pulls – Rolf Kristensen Jul 19 '23 at 18:59
  • I'm not offended - just surprised, _taken aback_, if you will. – Dai Jul 19 '23 at 19:00
  • @Dai Found a better link with available Azure File Share Operations: https://learn.microsoft.com/en-us/rest/api/storageservices/operations-on-files – Rolf Kristensen Jul 19 '23 at 19:03
  • @RolfKristensen That's the documentation for the (HTTP-based) REST web-service for Azure Files. It doesn't apply to VMs and Azure App Services mounting Azure Files Shares directly using SMB or NFS; it only applies to (usually external/on-prem) services that indirectly access Azure Files Shares via HTTP because SMB (generally) doesn't work over the public Internet (as many (if not most?) corporate firewalls and residential ISPs will block 445 to help stop the spread of malware that propagates over unsecured SMB). – Dai Jul 19 '23 at 19:05
  • @Dai If you are mounting as network-file-share (SMB / NFS), then I guess you can just use NLog FileTarget (`KeepFileOpen`=false). You didn't mention that you would do this in your initial question. See also: https://learn.microsoft.com/en-us/azure/storage/files/storage-how-to-use-files-windows + https://learn.microsoft.com/en-us/azure/storage/files/storage-how-to-use-files-linux – Rolf Kristensen Jul 19 '23 at 19:14
  • _"my initial question"_? I'm not the OP.... and I told the OP to use normal paths in my first comment. – Dai Jul 19 '23 at 19:27
  • 1
    Thanks guys for your helps. I used File target and i mounted an Azure File Share to AppService directory that contains logs. It works well! – Abdessalem MANAI Jul 20 '23 at 11:34

1 Answers1

0

Think there is a limitation with Azure File Shares, that file-append-operation is not available via REST-API. 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.

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

Rolf Kristensen
  • 17,785
  • 1
  • 51
  • 70