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.
OR
The LogWriter is already set.
...depending on the scenario.
The problem is that it throws an InvalidOperationException
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?
According to this CodePlex discussion,
The boostrapping behavior of Enterprise Library has changed in Version 6. The impact for the static Logger facade is that you need to set the internal
LogWriter
(for example at application start)
If you're in a web application scenario, Application_Start()
is the good way to do so:
protected void Application_Start()
{
Logger.SetLogWriter(new LogWriterFactory().Create());
}
Otherwise, set things up in Main()
method (or somewhere around it -- say, during container initialization).
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 downloading it and adding logic that does a check and additionally defining specific exceptions (see feature request):
LogWriterNotSetException
and LogWriterAlreadySetException
EDIT
Struck out forking as that would have licensing implications. Ownership has not been transfered for the Logging Application Block. Only Unity and Prism have been transferred.
According to a comment on the notice about the future of Unity, from a P & P member:
For the Logging Application Block, we consider it to be superceded by Semantic Logging (formerly Semantic Logging Application Block or SLAB).
https://github.com/mspnp/semantic-logging
In other words, we do not intend to work on the Logging Application Block and we have no plan to transfer it to new owners.
So best bet for anyone working on something new is trying out Semantic Logging
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With