خرید بک لینک

Vote count: 0

I am currently facing an issue related to logging messages in my WPF application.

I am keeping a static class for logging messages throughout my application which contains a function

private SomeService service = new SomeService();

private void LogMessage(string message)
{
   service.Log(message);
}

My issue is in my screens where I require logging, I append strings from different places in the screen and pass it to the LogMessage function. I have very large data to be logged from different places within the screen.

Now the issue I am facing is that a new member has been introduced ie

public bool IsLoggingEnabled = false;

Now I need to check this condition each time before appending the string like this

if(ClassName.IsLoggingEnabled)
{
    var msg = string.Format("Log 1 : {0}, Log 2 : {1}, Log 3 : {2} .... ", 0,1,2);
}

if(ClassName.IsLoggingEnabled)
{
    msg += string.Format("Log 4 : {0}, Log 5 : {1}, Log 6 : {2} .... ", 4,5,6);
}

...............

ClassName.LogMessage(msg);

Could you please suggest a solution for handling this scenario? Is it good to append all the messages and finally check the condition. Or check the condition within the LogMessage function?

But I felt these as wrong ways. Any suggestions would be appreciated.

asked 1 min ago

برچسب: نویسنده: استخدام کار تاريخ: دوشنبه 4 مرداد 1395 ساعت: 11:25

صفحه بندی