尝试获取LogWriter类型的实例时发生激活错误。 [英] Activation error occured while trying to get instance of type LogWriter.
问题描述
我正在尝试在安装时写入日志错误和异常。
我想在自定义安装程序类中的日志文件中写入错误和痕迹。
它正在安装后运行应用程序。我在安装程序类的install()自定义操作中有一个代码,我想在安装过程中打印跟踪和异常。但我得到以下优惠: -
========================== ================================================== ====================
Microsoft.Practices.ServiceLocation.ActivationException:尝试获取LogWriter类型的实例时发生激活错误,密钥 ---> Microsoft.Practices.Unity.ResolutionFailedException:依赖项的解析失败,type =Microsoft.Practices.EnterpriseLibrary.Logging.LogWriter,name =(none)。
异常发生时:while while resolving 。
异常是:InvalidOperationException - 无法构造LogWriter类型。您必须配置容器以提供此值。
-------------------------------- ---------------
在例外情况下,容器是:
解决Microsoft.Practices.EnterpriseLibrary.Logging.LogWriter,(无)
---> System.InvalidOperationException:无法构造LogWriter类型。您必须配置容器以提供此值。
at Microsoft.Practices.ObjectBuilder2.DynamicMethodConstructorStrategy.GuardTypeIsNonPrimitive(IBuilderContext context,SelectedConstructor selectedConstructor)
at Microsoft.Practices.ObjectBuilder2。 DynamicMethodConstructorStrategy.PreBuildUp(IBuilderContext context)
at Microsoft.Practices.ObjectBuilder2.StrategyChain.ExecuteBuildUp(IBuilderContext context)
at Microsoft.Practices.ObjectBuilder2.DynamicMethodBuildPlanCreatorPolicy.CreatePlan(IBuilderContext context ,NamedTypeBuildKey buildKey)
at Microsoft.Practices.ObjectBuilder2.BuildPlanStrategy.PreBuildUp(IBuilderContext context)
at Microsoft.Practices.ObjectBuilder2.StrategyChain.ExecuteBuildUp(IBuilderContext context)
at Microsoft.Practices.Unity.UnityContainer.DoBuildUp(Type t,Object existing,String name,IEnumerable`1 resolverOverrides)
---内部异常结束堆栈跟踪---
at Microsoft.Practices.Unity.UnityContainer.DoBuildUp(Type t,Object existing,String name,IEnumerable`1 resolverOverrides)
at Microsoft.Practices .Unity.UnityContainer.Resolve(Type t,String name,ResolverOverride [] resolverOverrides)
at Microsoft.Practices.Unity.UnityServiceLocator.DoGetInstance(Type serviceType,String key)
at Microsoft.Practices.ServiceLocation.ServiceLocatorImplBase.GetInstance(Type serviceType,String key)
---内部异常堆栈跟踪结束---
at Microsoft.Practices .ServiceLocation.ServiceLocatorImplBase.GetInstance(类型serviceType,String key)
at Microsoft.Practices.ServiceLocation.ServiceLocatorImplBase.GetInstance [TService]()
at LogManager.LogManager.WriteTraceLog (String traceMessage)
============================== ================================================== ===============
和我的app.config文件是这个::
========================= ================================================== ====================
< configuration>
< configsections>
< sectiongroup name =applicationSettingstype =System.Configuration.ApplicationSettingsGroup,System,Version = 4.0.0.0 ,Culture = neutral,PublicKeyToken = b77a5c561934e089>
< sectiongroup name =serviceSettingstype =System.Configuration.ApplicationSettingsGroup,System,Version = 4.0.0.0,Culture = neutral,PublicKeyToken = b77a5c561934e089>
< connectionstrings>
& lt; add name =DefaultConnectionconnectionstring =Data Source = | SQL / CE |>
< add name =DALmyapp.Properties.Settings.myapp_RTConnectionStringconnectionstring =Data Source = | DataDirectory | myapp.sdf;密码= cv3rt;持久安全信息= falseprovidername =Microsoft.SqlServerCe.Client.3.5>
< add name =myapp.Properties.Settings.myappConnectionString1>
connectionString =Data Source = | DataDirectory | \ App_Data \ myapp.sdf; Password = cv3rt
providerName =Microsoft.SqlServerCe.Client.3.5/> - >
< exceptionhandling>
< exceptionpolicies>
< add name =Exception>
< exceptiontypes>
< add name =All Exceptionstype =System.Exception,mscorlib,Version = 2.0.0.0,Culture = neutral,PublicKeyToken = b77a5c561934e089posthandlingaction =NotifyRethrow>
< exceptionhandlers>
< add name =Logging Exception Handlertype =Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Logging.LoggingExceptionHandler,Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Logging,Version = 5.0 .414.0,Culture = neutral,PublicKeyToken = 31bf3856ad364e35logcategory =Exceptioneventid =100severity =Errortitle =Enterprise Library Exception Handlingformattertype =Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.TextExceptionFormatter,Microsoft.Practices .EnterpriseLibrary.ExceptionHandlingpriority =0>
< add name =EmailException>
< exceptiontypes>
< add name =All Exceptionstype =System.Exception,mscorlib, Version = 2.0.0.0,Culture = neutral,PublicKeyToken = b77a5c561934e089posthandlingaction =NotifyRethrow>
< excepti onhandlers>
< add name =Logging Exception Handlertype =Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Logging.LoggingExceptionHandler,Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Logging,Version = 5.0.414.0 ,Culture = neutral,PublicKeyToken = 31bf3856ad364e35logcategory =EmailExceptioneventid =100severity =Errortitle =Enterprise Library Exception Handlingformattertype =Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.TextExceptionFormatter,Microsoft.Practices.EnterpriseLibrary .ExceptionHandlingpriority =0>
< loggingconfiguration name =tracingenabled =truedefaultcategory =General>
<听众> < add name =Event Log Listenertype =Microsoft.Practices.EnterpriseLibrary.Logging.TraceListeners.FormattedEventLogTraceListener,Microsoft.Practices.EnterpriseLibrary.Logging,Version = 5.0.414.0,Culture = neutral,PublicKeyToken = 31bf3856ad364e35listenerdatatype = Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.FormattedEventLogTraceListenerData,Microsoft.Practices.EnterpriseLibrary.Logging,Version = 5.0.414.0,Culture = neutral,PublicKeyToken = 31bf3856ad364e35source =Enterprise Library Loggingformatter =Text Formatterlog = machinename =。 traceoutputoptions =无>
< add name =电子邮件跟踪侦听器type =Microsoft.Practices.EnterpriseLibrary.Logging.TraceListeners.EmailTraceListener,Microsoft.Practices.EnterpriseLibrary.Logging,Version = 5.0.414.0,Culture = neutral,PublicKeyToken = 31bf3856ad364e35listenerdatatype =Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.EmailTraceListenerData,Microsoft.Practices.EnterpriseLibrary.Logging,Version = 5.0.414.0,Culture = neutral,PublicKeyToken = 31bf3856ad364e35toaddress =to@example.comfromaddress =from@example.comformatter =Text Formattertraceoutputoptions =None>
< add name =滚动平面文件异常监听器 type =Microsoft.Practices.EnterpriseLibrary.Logging.TraceListeners.RollingFlatFileTraceListener,Microsoft.Practices.EnterpriseLibrary.Logging,Version = 5.0.414.0,Culture = neutral,PublicKeyToken = 31bf3856ad364e35listenerdatatype =Microsoft.Practices.EnterpriseLibrary.Logging.Configuration。 RollingFlatFileTraceL istenerData,Microsoft.Practices.EnterpriseLibrary.Logging,Version = 5.0.414.0,Culture = neutral,PublicKeyToken = 31bf3856ad364e35filename =Log\UI_Errors.logformatter =Text Formatterrollfileexistsbehavior =Incrementrollinterval =Month rollsizekb =1024traceoutputoptions =无>
< add name =滚动平面文件跟踪侦听器type =Microsoft.Practices.EnterpriseLibrary.Logging.TraceListeners.RollingFlatFileTraceListener,Microsoft.Practices .EnterpriseLibrary.Logging,Version = 5.0.414.0,Culture = neutral,PublicKeyToken = 31bf3856ad364e35listenerdatatype =Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.RollingFlatFileTraceListenerData,Microsoft.Practices.EnterpriseLibrary.Logging,Version = 5.0.414.0,Culture =中性,PublicKeyToken = 31bf3856ad364e35filename =Log\UI_Traces.logformatter =Text Formatterrollinterval =Weekrollsizekb =1024traceoutputoptions =None>
< formatters> ;
< add type =Mi crosoft.Practices.EnterpriseLibrary.Logging.Formatters.TextFormatter,Microsoft.Practices.EnterpriseLibrary.Logging,Version = 5.0.414.0,Culture = neutral,PublicKeyToken = 31bf3856ad364e35template =Timestamp:{timestamp} {newline}消息:{message} {newline}类别:{category} {newline}优先级:{priority} {newline} EventId:{eventid} {newline}严重性:{severity} {newline}标题:{title} {newline}计算机:{localMachine} {newline App Domain:{localAppDomain} {newline} ProcessId:{localProcessId} {newline}进程名称:{localProcessName} {newline}线程名称:{threadName} {newline} Win32 ThreadId:{win32ThreadId} {newline}扩展属性:{字典({key} - {value} {newline})}name =Text Formatter>
< / formatters>
< categorysources>
< add switchvalue =Allname =General>
< listeners> < add name =Event Log Listener>
< add switchvalue =Allname =EmailException>
<听众> < add name =Email Trace Listener>
< add switchvalue =Allname =Exception>
<听众> < add name =Rolling Flat File Exception Listener>
< add switchvalue =Allname =Trace>
< listeners> < add name =Rolling Flat File Trace Listener>
< specialsources>
< allevents switchvalue =Allname =All Events>
< notprocessed switchvalue =Allname =Unprocessed Category>
< errors switchvalue =Allname =Logging Errors& Warnings>
< listeners> < add name =Event Log Listener>
任何帮助都会高度评价。
问候,
Tarun Giri
I am trying to write logs errors and exceptions at the time of installation.
i want to write errors and traces into log file inside custom installer class.
it is working with the application runs after installation. i have a code inside install() custom action of installer class where i i want to print traces and exceptions occurred during installation. but i am getting following excetion :-
================================================================================================
Microsoft.Practices.ServiceLocation.ActivationException: Activation error occured while trying to get instance of type LogWriter, key "" ---> Microsoft.Practices.Unity.ResolutionFailedException: Resolution of the dependency failed, type = "Microsoft.Practices.EnterpriseLibrary.Logging.LogWriter", name = "(none)".
Exception occurred while: while resolving.
Exception is: InvalidOperationException - The type LogWriter cannot be constructed. You must configure the container to supply this value.
-----------------------------------------------
At the time of the exception, the container was:
Resolving Microsoft.Practices.EnterpriseLibrary.Logging.LogWriter,(none)
---> System.InvalidOperationException: The type LogWriter cannot be constructed. You must configure the container to supply this value.
at Microsoft.Practices.ObjectBuilder2.DynamicMethodConstructorStrategy.GuardTypeIsNonPrimitive(IBuilderContext context, SelectedConstructor selectedConstructor)
at Microsoft.Practices.ObjectBuilder2.DynamicMethodConstructorStrategy.PreBuildUp(IBuilderContext context)
at Microsoft.Practices.ObjectBuilder2.StrategyChain.ExecuteBuildUp(IBuilderContext context)
at Microsoft.Practices.ObjectBuilder2.DynamicMethodBuildPlanCreatorPolicy.CreatePlan(IBuilderContext context, NamedTypeBuildKey buildKey)
at Microsoft.Practices.ObjectBuilder2.BuildPlanStrategy.PreBuildUp(IBuilderContext context)
at Microsoft.Practices.ObjectBuilder2.StrategyChain.ExecuteBuildUp(IBuilderContext context)
at Microsoft.Practices.Unity.UnityContainer.DoBuildUp(Type t, Object existing, String name, IEnumerable`1 resolverOverrides)
--- End of inner exception stack trace ---
at Microsoft.Practices.Unity.UnityContainer.DoBuildUp(Type t, Object existing, String name, IEnumerable`1 resolverOverrides)
at Microsoft.Practices.Unity.UnityContainer.Resolve(Type t, String name, ResolverOverride[] resolverOverrides)
at Microsoft.Practices.Unity.UnityServiceLocator.DoGetInstance(Type serviceType, String key)
at Microsoft.Practices.ServiceLocation.ServiceLocatorImplBase.GetInstance(Type serviceType, String key)
--- End of inner exception stack trace ---
at Microsoft.Practices.ServiceLocation.ServiceLocatorImplBase.GetInstance(Type serviceType, String key)
at Microsoft.Practices.ServiceLocation.ServiceLocatorImplBase.GetInstance[TService]()
at LogManager.LogManager.WriteTraceLog(String traceMessage)
===============================================================================================
and my app.config file is this ::
===============================================================================================
<configuration>
<configsections>
<sectiongroup name="applicationSettings" type="System.Configuration.ApplicationSettingsGroup, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<sectiongroup name="serviceSettings" type="System.Configuration.ApplicationSettingsGroup, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<connectionstrings>
<add name="DefaultConnection" connectionstring="Data Source = |SQL/CE|">
<add name="DALmyapp.Properties.Settings.myapp_RTConnectionString" connectionstring="Data Source=|DataDirectory|myapp.sdf;Password=cv3rt;Persist Security Info=false" providername="Microsoft.SqlServerCe.Client.3.5">
<add name="myapp.Properties.Settings.myappConnectionString1">
connectionString="Data Source=|DataDirectory|\App_Data\myapp.sdf;Password=cv3rt"
providerName="Microsoft.SqlServerCe.Client.3.5" />-->
<exceptionhandling>
<exceptionpolicies>
<add name="Exception">
<exceptiontypes>
<add name="All Exceptions" type="System.Exception, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" posthandlingaction="NotifyRethrow">
<exceptionhandlers>
<add name="Logging Exception Handler" type="Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Logging.LoggingExceptionHandler, Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Logging, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" logcategory="Exception" eventid="100" severity="Error" title="Enterprise Library Exception Handling" formattertype="Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.TextExceptionFormatter, Microsoft.Practices.EnterpriseLibrary.ExceptionHandling" priority="0">
<add name="EmailException">
<exceptiontypes>
<add name="All Exceptions" type="System.Exception, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" posthandlingaction="NotifyRethrow">
<exceptionhandlers>
<add name="Logging Exception Handler" type="Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Logging.LoggingExceptionHandler, Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Logging, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" logcategory="EmailException" eventid="100" severity="Error" title="Enterprise Library Exception Handling" formattertype="Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.TextExceptionFormatter, Microsoft.Practices.EnterpriseLibrary.ExceptionHandling" priority="0">
<loggingconfiguration name="" tracingenabled="true" defaultcategory="General">
<listeners> <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">
<add name="Email Trace Listener" type="Microsoft.Practices.EnterpriseLibrary.Logging.TraceListeners.EmailTraceListener, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" listenerdatatype="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.EmailTraceListenerData, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" toaddress="to@example.com" fromaddress="from@example.com" formatter="Text Formatter" traceoutputoptions="None">
<add name="Rolling Flat File Exception Listener" type="Microsoft.Practices.EnterpriseLibrary.Logging.TraceListeners.RollingFlatFileTraceListener, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" listenerdatatype="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.RollingFlatFileTraceListenerData, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" filename="Log\UI_Errors.log" formatter="Text Formatter" rollfileexistsbehavior="Increment" rollinterval="Month" rollsizekb="1024" traceoutputoptions="None">
<add name="Rolling Flat File Trace Listener" type="Microsoft.Practices.EnterpriseLibrary.Logging.TraceListeners.RollingFlatFileTraceListener, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" listenerdatatype="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.RollingFlatFileTraceListenerData, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" filename="Log\UI_Traces.log" formatter="Text Formatter" rollinterval="Week" rollsizekb="1024" traceoutputoptions="None">
<formatters>
<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}Message: {message}{newline}Category: {category}{newline}Priority: {priority}{newline}EventId: {eventid}{newline}Severity: {severity}{newline}Title:{title}{newline}Machine: {localMachine}{newline}App Domain: {localAppDomain}{newline}ProcessId: {localProcessId}{newline}Process Name: {localProcessName}{newline}Thread Name: {threadName}{newline}Win32 ThreadId:{win32ThreadId}{newline}Extended Properties: {dictionary({key} - {value}{newline})}" name="Text Formatter">
</formatters>
<categorysources>
<add switchvalue="All" name="General">
<listeners> <add name="Event Log Listener">
<add switchvalue="All" name="EmailException">
<listeners> <add name="Email Trace Listener">
<add switchvalue="All" name="Exception">
<listeners> <add name="Rolling Flat File Exception Listener">
<add switchvalue="All" name="Trace">
<listeners> <add name="Rolling Flat File Trace Listener">
<specialsources>
<allevents switchvalue="All" name="All Events">
<notprocessed switchvalue="All" name="Unprocessed Category">
<errors switchvalue="All" name="Logging Errors & Warnings">
<listeners> <add name="Event Log Listener">
Any help will be highly apeciated.
Regards,
Tarun Giri
推荐答案
这篇关于尝试获取LogWriter类型的实例时发生激活错误。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!