Activation error occured while trying to get instance of type LogWriter, key “”?

后端 未结 3 1438
长情又很酷
长情又很酷 2021-02-20 06:46

I have asp.net web site. I added reference of Microsoft.Practices.EnterpriseLibrary.Logging.dll to the site.

in web.cofig file, I defined like below.

3条回答
  •  借酒劲吻你
    2021-02-20 07:18

    Your full config references trace listeners that are not defined. This is causing the Enterprise Library runtime to throw a runtime exception when it tries to resolve those references.

    I commented out the unused listeners (and changed the default category to Important) and it is working:

    
    
        
            

    The clue is in the inner exception. At the end of the InnerException.Message it says:

    Resolving System.Diagnostics.TraceListener,Formatted EventLog TraceListener

    The above config is in app.config. Then Program.cs contains:

    class Program
    {
        static void Main(string[] args)
        {
            LogWriter logWriter = EnterpriseLibraryContainer.Current.GetInstance();
            logWriter.Write("Test");
         }
    }
    

提交回复
热议问题