Note that there are some explanatory texts on larger screens.

plurals
  1. POMVC 3, UNITY 2 and Enterprise Library 5 (Logging Application Block) - Activation error occured while trying to get instance of type LogWriter, key ""
    primarykey
    data
    text
    <p>I am playing around with MVC 3, with unity 2 and the Logging Application Block from Enterprise Library 5. When trying to make a simple log, I get the error listed below.</p> <p>I have really tried to search for answers, but no luck. Hope you have experience with this. </p> <p><strong>Error:</strong> Activation error occured while trying to get instance of type LogWriter, key ""</p> <p>Here is my configuration:</p> <p><strong>global.asax.cs</strong> </p> <pre><code>protected void Application_Start() { var container = new UnityContainer(); container.RegisterType&lt;IProductsRepository, ProductsRepository&gt;() } </code></pre> <p>The error occurs when I try to do the following: </p> <pre><code>if (Logger.IsLoggingEnabled()) </code></pre> <p>Note, I am currently running the webproject locally on my computer where the webconfig is defined to log to the Event log. More information of the error is given below: </p> <p><strong>Inner exception:</strong> {"The type LogWriter cannot be constructed. You must configure the container to supply this value."}</p> <p><strong>StackTrace:</strong> at Microsoft.Practices.ServiceLocation.ServiceLocatorImplBase.GetInstance(Type serviceType, String key) at Microsoft.Practices.ServiceLocation.ServiceLocatorImplBase.GetInstanceTService at Microsoft.Practices.EnterpriseLibrary.Logging.Logger.get_Writer() at Microsoft.Practices.EnterpriseLibrary.Logging.Logger.IsLoggingEnabled() at MyProject.Logging.LogManager.PerformLog(String message, String category, IDictionary<code>2 metaData, Exception ex, TraceEventType type, LogPriority priority) in C:\Work\MyProject\MyProject.WebUI\Infrastructure\LogManager.cs:line 163 at MyProject.Logging.LogManager.Info(String message) in C:\Work\MyProject\MyProject.WebUI\Infrastructure\LogManager.cs:line 103 at MyProject.WebUI.Controllers.ProductsController.List(String categoryName) in C:\Work\MyProject\MyProject.WebUI\Controllers\ProductsController.cs:line 34 at lambda_method(Closure , ControllerBase , Object[] ) at System.Web.Mvc.ActionMethodDispatcher.Execute(ControllerBase controller, Object[] parameters) at System.Web.Mvc.ReflectedActionDescriptor.Execute(ControllerContext controllerContext, IDictionary</code>2 parameters) at System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod(ControllerContext controllerContext, ActionDescriptor actionDescriptor, IDictionary<code>2 parameters) at System.Web.Mvc.ControllerActionInvoker.&lt;&gt;c__DisplayClass15.&lt;InvokeActionMethodWithFilters&gt;b__12() at System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodFilter(IActionFilter filter, ActionExecutingContext preContext, Func</code>1 continuation)</p> <hr> <p><strong>Here is my web.config file:</strong></p> <pre><code>&lt;?xml version="1.0"?&gt; &lt;configuration&gt; &lt;configSections&gt; &lt;section name="loggingConfiguration" type="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.LoggingSettings, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" requirePermission="true" /&gt; &lt;sectionGroup name="system.web.webPages.razor" type="System.Web.WebPages.Razor.Configuration.RazorWebSectionGroup, System.Web.WebPages.Razor, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"&gt; &lt;section name="host" type="System.Web.WebPages.Razor.Configuration.HostSection, System.Web.WebPages.Razor, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" /&gt; &lt;section name="pages" type="System.Web.WebPages.Razor.Configuration.RazorPagesSection, System.Web.WebPages.Razor, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" /&gt; &lt;/sectionGroup&gt; &lt;/configSections&gt; &lt;loggingConfiguration name="" tracingEnabled="true" defaultCategory="General"&gt; &lt;listeners&gt; &lt;add name="Event Log Listener" type="Microsoft.Practices.EnterpriseLibrary.Logging.TraceListeners.FormattedEventLogTraceListener, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" listenerDataType="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.FormattedEventLogTraceListenerData, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" source="Enterprise Library Logging" formatter="Text Formatter" log="" machineName="." traceOutputOptions="None" /&gt; &lt;/listeners&gt; &lt;formatters&gt; &lt;add type="Microsoft.Practices.EnterpriseLibrary.Logging.Formatters.TextFormatter, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" template="Timestamp: {timestamp}{newline}&amp;#xA;Message: {message}{newline}&amp;#xA;Category: {category}{newline}&amp;#xA;Priority: {priority}{newline}&amp;#xA;EventId: {eventid}{newline}&amp;#xA;Severity: {severity}{newline}&amp;#xA;Title:{title}{newline}&amp;#xA;Machine: {localMachine}{newline}&amp;#xA;App Domain: {localAppDomain}{newline}&amp;#xA;ProcessId: {localProcessId}{newline}&amp;#xA;Process Name: {localProcessName}{newline}&amp;#xA;Thread Name: {threadName}{newline}&amp;#xA;Win32 ThreadId:{win32ThreadId}{newline}&amp;#xA;Extended Properties: {dictionary({key} - {value}{newline})}" name="Text Formatter" /&gt; &lt;/formatters&gt; &lt;categorySources&gt; &lt;add switchValue="All" name="General"&gt; &lt;listeners&gt; &lt;add name="Event Log Listener" /&gt; &lt;/listeners&gt; &lt;/add&gt; &lt;/categorySources&gt; &lt;specialSources&gt; &lt;allEvents switchValue="All" name="All Events" /&gt; &lt;notProcessed switchValue="All" name="Unprocessed Category" /&gt; &lt;errors switchValue="All" name="Logging Errors &amp;amp; Warnings"&gt; &lt;listeners&gt; &lt;add name="Event Log Listener" /&gt; &lt;/listeners&gt; &lt;/errors&gt; &lt;/specialSources&gt; &lt;/loggingConfiguration&gt; &lt;appSettings&gt; &lt;add key="webpages:Enabled" value="false" /&gt; &lt;/appSettings&gt; &lt;system.web&gt; &lt;httpHandlers&gt; &lt;add path="*" verb="*" type="System.Web.HttpNotFoundHandler" /&gt; &lt;/httpHandlers&gt; &lt;!-- Enabling request validation in view pages would cause validation to occur after the input has already been processed by the controller. By default MVC performs request validation before a controller processes the input. To change this behavior apply the ValidateInputAttribute to a controller or action. --&gt; &lt;pages validateRequest="false" pageParserFilterType="System.Web.Mvc.ViewTypeParserFilter, System.Web.Mvc, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" pageBaseType="System.Web.Mvc.ViewPage, System.Web.Mvc, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" userControlBaseType="System.Web.Mvc.ViewUserControl, System.Web.Mvc, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"&gt; &lt;controls&gt; &lt;add assembly="System.Web.Mvc, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" namespace="System.Web.Mvc" tagPrefix="mvc" /&gt; &lt;/controls&gt; &lt;/pages&gt; &lt;/system.web&gt; &lt;system.webServer&gt; &lt;validation validateIntegratedModeConfiguration="false" /&gt; &lt;handlers&gt; &lt;remove name="BlockViewHandler" /&gt; &lt;add name="BlockViewHandler" path="*" verb="*" preCondition="integratedMode" type="System.Web.HttpNotFoundHandler" /&gt; &lt;/handlers&gt; &lt;/system.webServer&gt; &lt;system.web.webPages.razor&gt; &lt;host factoryType="System.Web.Mvc.MvcWebRazorHostFactory, System.Web.Mvc, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" /&gt; &lt;pages pageBaseType="System.Web.Mvc.WebViewPage"&gt; &lt;namespaces&gt; &lt;add namespace="System.Web.Mvc" /&gt; &lt;add namespace="System.Web.Mvc.Ajax" /&gt; &lt;add namespace="System.Web.Mvc.Html" /&gt; &lt;add namespace="System.Web.Routing" /&gt; &lt;/namespaces&gt; &lt;/pages&gt; &lt;/system.web.webPages.razor&gt; &lt;/configuration&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload