I'm trying to register a custom _async_ target and associated rule, programmatically.
When do I reference the target and when do I reference the async wrapper?
``` c#
var target = new MyCustomTarget();
var wrapper = new AsyncTargetWrapper(target, 5000, AsyncTargetWrapperOverflowAction.Discard);
var rule = new LoggingRule("*", LogLevel.Trace, target); // use "target" or "wrapper" here?
LogManager.Configuration.AddTarget("foo", wrapper); // use "target" or "wrapper" here?
LogManager.Configuration.LoggingRules.Add(rule);
LogManager.ReconfigExistingLoggers();
```
You code example should work. So, addTarget with the Wrapper and addRule with the target.
@migig Have your question been answered?
@Xharze @304NotModified What is the implication of addRule with wrapper instead of target?
So use wrapper for both addTarget and addRule.
I ask because it works both ways, but I'm worried it will lead to problems?
You should use the wrapper. The reason is that the asynchronous features are implemented in the wrapper not the target. If you pass in the target, you'll effectively bypass the asynchronous features of the wrapper. Both AddRule and AddTarget must use the wrapper.
The reason the rule must use the wrapper is that, when a logevent matches this rule it should be written to the wrapper.
The reason the target must use the wrapper is basically the same.
@Xharze Thanks that makes sense! :smile:
when you are instantiating rule you should pass wrapper instead of target to LoggingRule constructor.
Most helpful comment
You code example should work. So, addTarget with the Wrapper and addRule with the target.