0

I have two classes(A,B) and multiple threads are running. and one global variable in Class B, i am creating object of class B from class A

B objB = new B(_istry);
_istry is global variable in Class A and get modifies based on input

in Class B constructor is like this

public B(bool istry)
{
    IStry = istry;
}

so based on IStry value i am writing logs in different file.

if (IStry==TRUE)
---normal file path like (C:\log.txt)---
else
---modified file path (C:\IStry\log.txt)

this i want to do through log4net but i am not getting how to change folder based on one variable dynamically.

2
  • Easiest is to configure two separate loggers with two separate appenders, and get different loggers in the .GetLogger method in the constructor based on the variable. Slightly more involved is one logger with two appenders that filter based on an event property; this requires actually setting event properties, which means you have to explicitly construct events and can't use the ILog convenience methods. Alternatively, depending on the scope of what you're logging, a ThreadContext could be used to set the property. You could also filter by event message, if you're OK with changing that. Commented Jul 9, 2019 at 11:11
  • @JeroenMostert can you provide some example for this explanation. Commented Jul 9, 2019 at 13:56

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.