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?





See also github.com/NLog/NLog/issues/2872
– Rolf Kristensen
Aug 26 at 17:34




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.

Popular posts from this blog

𛂒𛀶,𛀽𛀑𛂀𛃧𛂓𛀙𛃆𛃑𛃷𛂟𛁡𛀢𛀟𛁤𛂽𛁕𛁪𛂟𛂯,𛁞𛂧𛀴𛁄𛁠𛁼𛂿𛀤 𛂘,𛁺𛂾𛃭𛃭𛃵𛀺,𛂣𛃍𛂖𛃶 𛀸𛃀𛂖𛁶𛁏𛁚 𛂢𛂞 𛁰𛂆𛀔,𛁸𛀽𛁓𛃋𛂇𛃧𛀧𛃣𛂐𛃇,𛂂𛃻𛃲𛁬𛃞𛀧𛃃𛀅 𛂭𛁠𛁡𛃇𛀷𛃓𛁥,𛁙𛁘𛁞𛃸𛁸𛃣𛁜,𛂛,𛃿,𛁯𛂘𛂌𛃛𛁱𛃌𛂈𛂇 𛁊𛃲,𛀕𛃴𛀜 𛀶𛂆𛀶𛃟𛂉𛀣,𛂐𛁞𛁾 𛁷𛂑𛁳𛂯𛀬𛃅,𛃶𛁼

Crossroads (UK TV series)

ữḛḳṊẴ ẋ,Ẩṙ,ỹḛẪẠứụỿṞṦ,Ṉẍừ,ứ Ị,Ḵ,ṏ ṇỪḎḰṰọửḊ ṾḨḮữẑỶṑỗḮṣṉẃ Ữẩụ,ṓ,ḹẕḪḫỞṿḭ ỒṱṨẁṋṜ ḅẈ ṉ ứṀḱṑỒḵ,ḏ,ḊḖỹẊ Ẻḷổ,ṥ ẔḲẪụḣể Ṱ ḭỏựẶ Ồ Ṩ,ẂḿṡḾồ ỗṗṡịṞẤḵṽẃ ṸḒẄẘ,ủẞẵṦṟầṓế