6

HI allí,EntLib5: Bloque de aplicación de inicio de sesión que no se registra en el registro de eventos (excepción: escriba LogWriter no se puede construir) - ¿Alguien puede ayudar?

Acabo de configurar la parte del bloque de la aplicación de registro de Enterprise Library 5. Creo que lo he hecho correctamente pero no está registrando en el registro de eventos errores en el método de escritura y me da la siguiente excepción.

The type LogWriter cannot be constructed. 
     You must configure the container to supply this value. 

¿Alguien puede hacer un cheque o dime lo que me falta ..

En primer lugar estoy corriendo en Windows 7 con una aplicación de Windows Forms.

Aquí está mi método que crea el registro y ve el método de escritura.

public class Logger : ILogger 
{ 
    public void SendTest(string test) 
    { 
     LogEntry log = new LogEntry(); 
     log.EventId = 300; 
     log.Message = test; 
     log.Categories.Add("testing"); 
     log.Severity = TraceEventType.Information; 
     log.Priority = 5; 
     Microsoft.Practices.EnterpriseLibrary.Logging.Logger.Write(log); 

    } 
} 

Todas mis configuraciones se construyeron usando el editor entlib5 y no a mano. Y confirmó esta portofino la ruta donde entlib.config es

filePath="C:\myapp\entlib.config" /> 

Aquí es mi app.config que apunta a mi entlib.config

<?xml version="1.0"?> 
<configuration> 
<configSections> 
    <section name="enterpriseLibrary.ConfigurationSource" type="Microsoft.Practices.EnterpriseLibrary.Common.Configuration.ConfigurationSourceSection, Microsoft.Practices.EnterpriseLibrary.Common, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" requirePermission="true" /> 
</configSections> 
<enterpriseLibrary.ConfigurationSource selectedSource="System Configuration Source"> 
    <sources> 
     <add name="System Configuration Source" type="Microsoft.Practices.EnterpriseLibrary.Common.Configuration.SystemConfigurationSource, Microsoft.Practices.EnterpriseLibrary.Common, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" /> 
     <add name="File-based Configuration Source" type="Microsoft.Practices.EnterpriseLibrary.Common.Configuration.FileConfigurationSource, Microsoft.Practices.EnterpriseLibrary.Common, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" 
      filePath="C:\myapp\entlib.config" /> 
    </sources> 
    <redirectSections> 
     <add sourceName="File-based Configuration Source" name="Redirected Section" /> 
    </redirectSections> 
</enterpriseLibrary.ConfigurationSource> 
<startup><supportedRuntime version="v2.0.50727"/></startup></configuration> 

y aquí está mi entlib.config

<?xml version="1.0" encoding="utf-8" ?> 
<configuration> 
    <configSections> 
     <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" /> 
    </configSections> 
    <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" /> 
     </listeners> 
     <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}&#xA;Message: {message}{newline}&#xA;Category: {category}{newline}&#xA;Priority: {priority}{newline}&#xA;EventId: {eventid}{newline}&#xA;Severity: {severity}{newline}&#xA;Title:{title}{newline}&#xA;Machine: {localMachine}{newline}&#xA;App Domain: {localAppDomain}{newline}&#xA;ProcessId: {localProcessId}{newline}&#xA;Process Name: {localProcessName}{newline}&#xA;Thread Name: {threadName}{newline}&#xA;Win32 ThreadId:{win32ThreadId}{newline}&#xA;Extended Properties: {dictionary({key} - {value}{newline})}" 
       name="Text Formatter" /> 
     </formatters> 
     <categorySources> 
      <add switchValue="All" name="General"> 
       <listeners> 
        <add name="Event Log Listener" /> 
       </listeners> 
      </add> 
     </categorySources> 
     <specialSources> 
      <allEvents switchValue="All" name="All Events" /> 
      <notProcessed switchValue="All" name="Unprocessed Category" /> 
      <errors switchValue="All" name="Logging Errors &amp; Warnings"> 
       <listeners> 
        <add name="Event Log Listener" /> 
       </listeners> 
      </errors> 
     </specialSources> 
    </loggingConfiguration> 
</configuration> 

EDIT La pregunta se ha actualizado con la nueva aplicación.config, para incluir

<redirectSections> 
    <add sourceName="File-based Configuration Source" name="Redirected Section" /> 
</redirectSections> 

Todavía me aparece un error.

Activation error occured while trying to get instance of type 

LogWriter, tecla ""

y excepción interna es

Resolución de la dependencia fracasó, type = \ "Microsoft.Practices.EnterpriseLibrary.Logging. LogWriter \ ", name = \" (none) \ ". \ R \ nExcepción ocurrida mientras: while resolv ing. \ r \ nException es: InvalidOperationException - No se puede construir el tipo LogWriter. Usted debe configurar el contenedor para suministrar este valor . \ R \ n --------------------------------- -------------- \ r \ nEn el momento de la excepción, el contenedor era: \ r \ n \ r \ n Resolviendo Microsoft.Practices.EnterpriseLibrary.Logging.LogWriter, (ninguno) \ r \ n "}

que utiliza el configurador EntLib para crear dos archivos.

el entlib.config acepté el defecto, ya que parece tener el oyente EventLog incluido ..

EDITAR

este ermm es mi línea en el archivo entlib.config, registro se empty-- es esto correcto?

<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" /> 

EDITAR

MI Logger.write está en una DLL pero mi app.config/entlib.config están en una aplicación Windows Forms .. la aplicación Windows Forms tiene una referencia al proyecto DLL donde i escribe el registro

Tanto el DLL y los winforms tiene una referencia a

Microsoft.Practices.EnterpriseLibrary.Logging 

y también utilizando la unidad, tiene

Microsoft.Practices.Unity 

    Microsoft.Practices.Unity.Interception 

Respuesta

3

Martin, que ha creado una fuente de configuración basada en archivos, pero no lo has redirigió la sección de registro a ella.

Agregue lo siguiente al App.config dentro del nodo enterpriseLibrary.ConfigurationSource:

<redirectSections> 
     <add sourceName="File-based Configuration Source" name="loggingConfiguration" /> 
</redirectSections> 

Además, recomiendo las fuentes de configuración laboratorios del conjunto Enterprise Library 5.0 Hands-on Labs. Cubre esto y escenarios más avanzados.

+0

Gracias grigori, sí, me falta esto, ahora lo he actualizado ... actualizaré mi pregunta ... Todavía está fallando. ¿Algunas ideas? – Martin

Cuestiones relacionadas