How to check if LogWriter is installed?

I am trying to handle the LogWriter Enterprise Library 6 exception that has recently appeared after an upgrade from Enterprise Library 4-6.

I either get:

LogWriter is not installed for the static Logger class. Install it by calling the Logger.SetLogWriter method.

OR

LogWriter is already installed.

... depending on the scenario.

The problem is that it throws an InvalidOperationException that seems too general to handle, and that even checking with

 if (Logger.Writer == null) 

... also gives an exception, since it would be possible to check if the script is installed or not?

+8
c # logging exception-handling enterprise-library-6
source share
2 answers

Thanks for the answers and comments.

I looked at the project code and saw that there was nothing in it that supported this.

Despite the fact that the project is no longer being developed, I took the opportunity and posted a function request .

The best scenario for achieving this requirement would be to download forking and add logic that will check and additionally identify specific exceptions (see function request):

LogWriterNotSetException and LogWriterAlreadySetException

EDIT

It is emphasized that this will have consequences for licensing. The property has not been transferred to the Registration Application Block. Only Unity and Prism were ported .

According to the comment on Unity's future notice from member P and P:

For the block of logging applications, we consider its semantic registration (previously, the block of semantic logging applications or overlapping was applied).

https://github.com/mspnp/semantic-logging

In other words, we are not going to work on the Block Records, and we do not plan to transfer it to new owners.

So, the best option for anyone who is working on something new is trying Semantic Registration

+1
source share

According to this discussion of CodePlex ,

Version 6 has changed the behavior of Enterprise Library convergence. The effect on the static phase of Logger is that you need to install an internal LogWriter (for example, when starting the application)

If you are in a web application script, Application_Start() is a good way to do this:

 protected void Application_Start() { Logger.SetLogWriter(new LogWriterFactory().Create()); } 

Otherwise, set the values ​​in the Main() method (or somewhere around it - say, during container initialization).

+2
source share

All Articles