NLog File Icon and keepFileOpen Flag

The FileTarget in NLog has a property (bool) called "keepFileOpen". By default, this property is set to false, which means that each log event will open a file, write to a file, and close the file.

The performance hit is huge, so I pointed "keepFileOpen" to true, not false, which means the file will be opened only once.

Does anyone have an idea (or just know) why this property is set to false by default, and does HOGGE performance affect the recording?

Are there any scenarios when setting this property to true can cause problems (therefore, it would be wise to default to false).

Thanks!

EDIT

Performance measurements for the basic layout, writing 100K events to the log:

  • keepFileOpen = false (default): ~ 101 s
  • keepFileOpen = true: ~ 1 s
+6
source share
2 answers

I will try to send them an email and ask them about it. I cannot understand why this option is incorrect by default.

0
source

I would say closing a file is the expected behavior. If you try to access a file from another process or delete it in the file system while the Nlog process is active, this will lead to those annoying system errors that say that some process contains a file, etc.

If the file open time is too long for you, try using AsyncWrapper and you will get fire-and-forget behavior.

Therefore, I believe that the default value is ok.

+5
source

Source: https://habr.com/ru/post/920080/


All Articles