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

BatchSize in appsettings.json not working? #155

Open symlynk opened 6 months ago

symlynk commented 6 months ago

How would I go about setting the batchSize and taskDelayMilliseconds using appsettings.json? The following doesn't appear to be working as I'm hitting the 50000 block limit with similar number of lines in the log no matter what values I use.

"NLog": {
    "extensions": [
        {
            "assembly": "NLog.Web.AspNetCore"
        },
        {
            "assembly": "NLog.Extensions.AzureBlobStorage"
        }
    ],
    "targets": {
        "blob": {
            "type": "AzureBlobStorage",
            "blobName": "${logger}/${shortdate:universalTime=True}.log",
            "connectionString": "${configsetting:ConnectionStrings.Storage}",
            "container": "logs",
            "batchSize": 1000,
            "taskDelayMilliseconds": 1000
        }
    },
    "rules": [
        {
            "logger": "*",
            "minLevel": "Trace",
            "writeTo": "blob"
        }
    ]
}
snakefoot commented 6 months ago

I'm not an expert on Azure Blob Storage, so you will probably find better advice on StackOverflow.com

When troubleshooting NLog then it is always a good idea to enable "throwConfigExceptions": true. It can also be a good idea to enable NLog InternalLogger to see what NLog Configuration is applied.

Are you by any chance running multiple nodes against the same Azure-Blob, thus having multiple nodes performing 30000 appends, thus exceeding the max total of 50000 writes ?

symlynk commented 6 months ago

The internal log shows no errors or any mention of batchSize or taskDelayMilliseconds using "internalLogLevel": "trace" and "throwConfigExceptions": true. I can see the target being successfully registered.

There is only a single instance of the application writing to this log which is writing around 2000 lines per second in trace mode.

snakefoot commented 6 months ago

If you write 2000 lines/per-sec, and using BatchSize=1000, then I guess you are performing 2 appends-per-sec.

And single blob can only handle 50000-appends, and you create single blob-per-day. So 50000 / 24 hours / 60 min = Max 34 appends-per-min.

Maybe change from daily to hourly: "blobName": "${logger}/${date:format=yyyy-MM-dd-HH:universalTime=true}.log"

snakefoot commented 6 months ago

You probably have to increase taskDelayMilliseconds to avoid trigger write before having a full batchSize:

        "blob": {
            "type": "AzureBlobStorage",
            "blobName": "${logger}/${shortdate:universalTime=True}.log",
            "connectionString": "${configsetting:ConnectionStrings.Storage}",
            "container": "logs",
            "batchSize": 10000,
            "taskDelayMilliseconds": 5000
        }

Again probably easier to change from daily to hourly: "blobName": "${logger}/${date:format=yyyy-MM-dd-HH:universalTime=true}.log"

See also: https://stackoverflow.com/q/78483889/193178