This isn't really a different answer than @Nobby, because he is right about how to the levels. I will say that you don't have to do the IfXXXXEnabled check before logging This is what you currently have in your C# code in your question for your logging call site: if (logger. IsDebugEnabled) logger.
Debug(logMessage) else if (logger. IsInfoEnabled)log. Info(logMessage) Nobby suggests, this could be made cleaner by doing this: if (logger.
IsDebugEnabled) logger. Debug(logMessage); if (logger. IsInfoEnabled) logger.Info(logMessage) I don't think that is really true.
With your original code, ONLY the Debug message OR the Info message will be logged. If you remove the nesting, then, depending on the logging level that is enabled, you could get BOTH messages logged I think you should be logging this way: logger. Debug(logMessage); logger.
Info(logMessage) The logging methods (logger. Debug, logger.Info, etc) already do an IsXXXEnabled check and won't log if that logging level is not enabled. You can save a log of typing (and confusion) by just making the logging call directly rather than protecting it with the if check There are times when you want to use the IsXXXEnabled check.
Such as if you have some work to do to calculate the value(s) to be logged and you only want do that calculation if you are logging: if (logger. IsDebugEnabled) { int value1 = DoSomeExpensiveCalculation(); int value2 = DoSomeOtherExpensiveCalculation(); logger. DebugFormat("v1 = {0}, v2 = {1}", value1, value2); } This way you are not paying the price of the calculations unless you are actually going to log them Finally, in NLog 2.0 you have access to lambda syntax that would allow you to defer potentially expensive operations unless the message is actually logged: logger.
Debug(() => string. Format("v1 = {0}, v2 = {1}", DoSomeExpensiveCalculation(), DoSomeOtherExpensiveCalculation())); logger. Debug(() => "message" + I + ", " + j + "," + k) In both cases, the expression that is being passed to NLog will not be evaluated unless the DEBUG level is enabled.
This isn't really a different answer than @Nobby, because he is right about how to the levels. I will say that you don't have to do the IfXXXXEnabled check before logging. This is what you currently have in your C# code in your question for your logging call site: if (logger.
IsDebugEnabled) logger. Debug(logMessage) else if (logger. IsInfoEnabled)log.Info(logMessage); @Nobby suggests, this could be made cleaner by doing this: if (logger.
IsDebugEnabled) logger. Debug(logMessage); if (logger. IsInfoEnabled) logger.
Info(logMessage); I don't think that is really true. With your original code, ONLY the Debug message OR the Info message will be logged. If you remove the nesting, then, depending on the logging level that is enabled, you could get BOTH messages logged.
I think you should be logging this way: logger. Debug(logMessage); logger.Info(logMessage); The logging methods (logger. Debug, logger.
Info, etc) already do an IsXXXEnabled check and won't log if that logging level is not enabled. You can save a log of typing (and confusion) by just making the logging call directly rather than protecting it with the if check. There are times when you want to use the IsXXXEnabled check.
Such as if you have some work to do to calculate the value(s) to be logged and you only want do that calculation if you are logging: if (logger. IsDebugEnabled) { int value1 = DoSomeExpensiveCalculation(); int value2 = DoSomeOtherExpensiveCalculation(); logger. DebugFormat("v1 = {0}, v2 = {1}", value1, value2); } This way you are not paying the price of the calculations unless you are actually going to log them.
Finally, in NLog 2.0 you have access to lambda syntax that would allow you to defer potentially expensive operations unless the message is actually logged: logger. Debug(() => string. Format("v1 = {0}, v2 = {1}", DoSomeExpensiveCalculation(), DoSomeOtherExpensiveCalculation())); logger.
Debug(() => "message" + I + ", " + j + "," + k); In both cases, the expression that is being passed to NLog will not be evaluated unless the DEBUG level is enabled.
Your problem lies with the nested if statements in your example. Both Debug and Info log levels are enabled according to your config file. The first if statement is then evaluated and its block executed because the condition is true.
The else block is therefore never reached and your Info message is never logged. I suggest that you split your nested if statements into 2 separate statements if you want to log the message for Debug and Info levels.
I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.