Hi,
I have wrote my own custom target by inherit from the TargetWithLayout. My custom target will log to database but in some cases this could fail. I still needs to log in some way so the question is if its possible to call a known target like the EventLogTarget from within the custom target and then log there? Or do I have to create the EvenLog code manually within the CustomTarget?
What about the fallback target? https://github.com/NLog/NLog/wiki/FallbackGroup-target
or writing to both always? (e.g. <logger ... writeto=myTarget,eventLogger`
Thanks!
That looks like a good way to do it but how will it know if one failes? From what I have seen there is really not much happening after a exception is thrown from within a custom target. I do not get a carscading exception to the calling code it just dont log anything. Will nlog note the exception in the customTarget and then try the next target in config?
<targets>
<target xsi:type="FallbackGroup" name="String" returnToFirstOnSuccess="Boolean">
<target xsi:type="CustomMail" ... />
<target xsi:type="Evenlog" ... />
</target>
</targets>
So if the mail is failing in the above with an exception the Evenlog will and only then be used? I dont wnat to log to 2 targets at the same time, it would generate more data then needed.
So if the mail is failing in the above with an exception the Evenlog will and only then be used?
NLog attaches a lambda-function to each logevent (AsyncLogEventInfo). This lamba-function is called by the destination target on logevent-write-completion (both on success or on exception).
The fallback-wrapper attaches/chains its own delegate to the logevent-lambda, and when the destination-target calls the logevent-lambda, then the fallback-wrapper is notified whether the logevent-write completed with an exception. On exception then the attached fallback-wrapper-lambda will redirect the logevent to the specified fallback-target.
The short answer is that the fallback-wrapper will only call the fallback-target, when the primary target fails with an exception.
Thanks!