user919426 user919426 - 1 year ago 577
C# Question

How to check if LogWriter has been set?

I am trying to handle an Enterprise Library 6 LogWriter Exception that has recently popped up after upgrading from Enterprise Library 4 to 6.

I either get:

The LogWriter has not been set for the Logger static class. Set it
invoking the Logger.SetLogWriter method.


The LogWriter is already set.

...depending on the scenario.

The problem is that it throws an
which seems too generic to handle, and that even checking using

if (Logger.Writer == null)

... also yields an exception, so how would one then check if the writer is set or not?

Answer Source

Thanks for the answers and comments.

I have looked through the project's code and seen that there is nothing built into it that supports this.

Even though the project is no longer under development, I took a chance and posted a feature request.

Best scenario to achieve this requirement would be forking it and adding logic that does a check and additionally defining specific exceptions (see feature request):

LogWriterNotSetException and LogWriterAlreadySetException