A FileTarget object in NLog has a property (bool) called "keepFileOpen". By default this property is set to false, meaning that each log event will open the file, write in the file and close the file.
The hit in performance is huge, so I specified "keepFileOpen" to true, instead of false, meaning that the file will be opened only once.
Does anybody has an idea (or just know) why this property is by default set to "false", incuring a HUGE performance hit on logging ?
Is there any scenarios where setting this property to true can cause issues (which would therefore make sense to default it to "false").
Thanks !
EDIT
Performance measurements for basic layout, writing 100K events to the logger :
Targets - the destinations of a logevent, e.g. file, database, console. Layout - the layout e.g. json, csv, plain-text (default)
NLog is a . Net Library that enables you to add high-quality logs for your application. NLog can also be downloaded using Nugget in Visual Studio. Targets are used to display, store, or pass log messages to another destination.
NLog supports semantic/structured logging known from similar frameworks like Serilog and Microsoft. Extensions. Logging. With structured logging, you no longer log just simple text messages.
I would say that closing the file is the expected behaviour. If you will try to access the file from another process or delete it in file system while the NLog-process is alive it would lead to those annoying system-errors saying that some process holds the file etc.
If the time of opening a file is too long for you, try using the AsyncWrapper and you'll get a fire-and-forget-behavior.
Therefore I think that the default value is ok.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With