Using throwExceptions

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Using throwExceptions

wildlogger
I have the following code (in a simple console application). I am using an app.config file to record the nlog settings. throwExceptions='true' in the config file, and a set of targets are defined (console, text file, event log and email). The targets all work and follow the rules set for them. static void simpleLoggerTest() { Console.WriteLine(string.Format("Start with throwExceptions = {0}", LogManager.ThrowExceptions.ToString())); // Note 1 LogManager.ThrowExceptions = true; Console.WriteLine(string.Format("Set throwExceptions = {0}", LogManager.ThrowExceptions.ToString())); Logger logger = LogManager.GetLogger("Foobar"); try { logger.Info("Test message from simple logger"); // Note 2 } catch (NLogRuntimeException ex) { Console.WriteLine(string.Format("Nlog Exception : {0}", ex.Message)); // Note 3 } } I have a number of issues; 1. Despite the throwExceptions settings, the first writeline displays 'false', unless i hover over the LogManager in Visual Studio to reveal the internals, after which the LogManager.ThrowExceptions becomes 'true'. It looks like the configuration isnt being properly read until all the properties of LogManager have been read. 2. Whilst stepping through the code the intelliTrace output shows that logger.Info generates an exception 'Input string was not in a correct format' - how can this be? I note that the exception is both raised and caught - i would expect the throwExceptions settings to cause an exception to be raised? 3. If i set the smtp server name incorrectly in order to generate an exception then intelliTrace shows a series of exceptions resulting from the error (as expected). Trouble is that they are all raised and caught - so my 'catch' block doesnt get a look in. Why is this? All help gratefully received.
Reply | Threaded
Open this post in threaded view
|

Re: Using throwExceptions

wildlogger
Hopefully this is formatted better!

I have the following code (in a simple console application).
I am using an app.config file to record the nlog settings.
throwExceptions='true' in the config file, and a set of targets are defined (console, text file, event log and email).
The targets all work and follow the rules set for them.

static void simpleLoggerTest()
{
        Logger logger = LogManager.GetLogger("Foobar");  // Note 1

        Console.WriteLine(string.Format("Start with throwExceptions = {0}", LogManager.ThrowExceptions.ToString()));

        LogManager.ThrowExceptions = true;
        Console.WriteLine(string.Format("Set throwExceptions = {0}", LogManager.ThrowExceptions.ToString()));

        try
        {
                logger.Info("Test message from simple logger"); // Note 2
        }
        catch (NLogRuntimeException ex)
        {
                Console.WriteLine(string.Format("Nlog Exception : {0}", ex.Message)); // Note 3
        }
}

I have a number of issues;
1. Despite the throwExceptions settings, the first writeline displays 'false', unless i hover over the LogManager in Visual Studio to reveal the internals, after which the LogManager.ThrowExceptions becomes 'true'. It looks like the configuration isnt being properly read until all the properties of LogManager have been read.
2. Whilst stepping through the code the intelliTrace output shows that logger.Info generates an exception 'Input string was not in a correct format' - how can this be? I note that the exception is both raised and caught - i would expect the throwExceptions settings to cause an exception to be raised?
3. If i set the smtp server name incorrectly in order to generate an exception then intelliTrace shows a series of exceptions resulting from the error (as expected). Trouble is that they are all raised and caught - so my 'catch' block doesnt get a look in. Why is this?

All help gratefully received.