what is the difference between AsyncTaskTarget and AsyncWrapper Target in NLog 4.5?
what is the difference between AsyncTaskTarget and AsyncWrapper Target in NLog 4.5?
What is the difference between AsyncTaskTarget and AsyncWrapper?
Which is better?
I have seen that AsyncWrapper has more config options (like queueLimit, overflowAction & more) which is important for me (I don't want logs to get discarded, even if more than 10000 logs buffered, since I am working on a website for some big company).
So, is that the only difference?
Why then we even have something like AsyncTaskTarget?
Moreover, what happens if I combined both AsyncTaskTarget & AsyncWrapper with something like this:
CustomTargetExtendingAsyncTaskTarget customTarget = CustomTargetExtendingAsyncTaskTarget();
AsyncTargetWrapper asyncTargetWrapper = new AsyncTargetWrapper(customTarget, 100000, AsyncTargetWrapperOverflowAction.Grow);
is this a bad idea?
1 Answer
1
In summary:
The AsyncTarget is a target to wrap around other targets to give them Async behavior. Good to know, the async=true
that could be applied in the nlog.config is internally also the AsyncWrapper.
async=true
For example, writing async to a file:
<target name="target2" xsi:type="AsyncWrapper">
<target name ="target1" xsi:type="File"
fileName="c:/temp/test.log" layout="$message"
keepFileOpen="true" />
</target>
The AsyncTaskTarget is an (abstract) base class for creating custom targets (e.g. in C#) with async behavior. You cannot use the AsyncTaskTarget in your nlog.config
Rolf describes it nicely:
(from https://github.com/NLog/NLog/issues/2872)
AsyncTaskTarget is a base-class just like TargetWithLayout for creating your own custom Target. It makes it easier to make one chain of tasks with timeout-handling. By default it will ensure the Logger is not stalled, as it just writes to the internal-queue (and schedules a writer-task if none is active).
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.
See also github.com/NLog/NLog/issues/2872
– Rolf Kristensen
Aug 26 at 17:34