2015-11-20 4 views
1

J'ai un service Windows qui utilise ELAB comme connexion. Lors de l'exécution du service en mode console, toute la journalisation fonctionne correctement. Mais dès que je démarre en tant que service, aucune journalisation ne se produit.EntLib V6 Connexion au sein d'un service Windows

choses que j'ai vérifié:

  • vérifié les autorisations de dossier et
  • couru le service en mode console de l'utilisateur qui est utilisé par le service
  • utilisé Procmon pour vérifier s'il y avait même un essai pour créer un fichier journal
  • utilisé chemin absolu et par rapport à spécifier le fichier journal

Je n'ai pas la moindre idée pourquoi cela ne fonctionne pas.

Pour initialiser l'enregistrement:

try 
{ 
    var config = new SystemConfigurationSource(true, 30000); 
    var logWriterFactory = new LogWriterFactory(config); 
    LogWriter = logWriterFactory.Create(); 
    Logger.SetLogWriter(LogWriter, false); 
} 
catch (Exception ex) 
{ 
    var msg = $"{DateTime.Now:yyyy-MM-dd HH:mm:ss} Error loading configuration. {ex}"; 
    File.WriteAllText(Environment.ExpandEnvironmentVariables("%TEMP%\\mayflower_logging_error.txt"), msg); 
    Debug.WriteLine(msg); 
} 

Et ma configuration elab:

<enterpriseLibrary.ConfigurationSource selectedSource="Mayflower"> 
    <sources> 
     <add name="Mayflower" 
      type="Microsoft.Practices.EnterpriseLibrary.Common.Configuration.SystemConfigurationSource, Microsoft.Practices.EnterpriseLibrary.Common, Version=6.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" /> 
    </sources> 
</enterpriseLibrary.ConfigurationSource> 
<loggingConfiguration name="ServiceLogging" tracingEnabled="true" defaultCategory="General" 
         logWarningsWhenNoCategoriesMatch="false" revertImpersonation="false"> 
    <listeners> 
     <add name="Logfile" 
      type="Microsoft.Practices.EnterpriseLibrary.Logging.TraceListeners.RollingFlatFileTraceListener, Microsoft.Practices.EnterpriseLibrary.Logging, Version=6.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" 
      listenerDataType="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.RollingFlatFileTraceListenerData, Microsoft.Practices.EnterpriseLibrary.Logging, Version=6.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" 
      fileName="Logs\Mayflower-Server.log" footer="::: Message End :::" 
      formatter="Detailed" header="" rollFileExistsBehavior="Increment" 
      rollInterval="Midnight" rollSizeKB="50000" traceOutputOptions="LogicalOperationStack, DateTime" 
      asynchronous="true" /> 
     <add 
      listenerDataType="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.CustomTraceListenerData, Microsoft.Practices.EnterpriseLibrary.Logging, Version=6.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" 
      type="Mayflower.Server.Core.ConsoleTraceListener, Mayflower.Server.Core, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" 
      filter="Information" name="Console" formatter="Short" /> 
    </listeners> 
    <formatters> 
     <add 
      type="Microsoft.Practices.EnterpriseLibrary.Logging.Formatters.TextFormatter, Microsoft.Practices.EnterpriseLibrary.Logging, Version=6.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" 
      template="{timestamp} {category} {message}{newline} Priority: {priority} EventId: {eventid} Severity: {severity} Thread Name: {threadName}{newline} Extended Properties: {dictionary({key} - {value}{newline})}" 
      name="Detailed" /> 
     <add 
      type="Microsoft.Practices.EnterpriseLibrary.Logging.Formatters.TextFormatter, Microsoft.Practices.EnterpriseLibrary.Logging, Version=6.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" 
      template="{timestamp(FixedFormatTime)} {category} {message}{newline}" 
      name="Short" /> 
    </formatters> 
    <categorySources> 
     <add switchValue="All" name="General"> 
      <listeners> 
       <add name="Console" /> 
       <add name="Logfile" /> 
      </listeners> 
     </add> 
    </categorySources> 
    <specialSources> 
     <allEvents switchValue="All" name="All Events"> 
      <listeners> 
       <add name="Logfile" /> 
       <add name="Console" /> 
      </listeners> 
     </allEvents> 
     <notProcessed switchValue="All" name="Unprocessed Category"> 
      <listeners> 
       <add name="Console" /> 
       <add name="Logfile" /> 
      </listeners> 
     </notProcessed> 
     <errors switchValue="All" name="Logging Errors &amp; Warnings"> 
      <listeners> 
       <add name="Logfile" /> 
       <add name="Console" /> 
      </listeners> 
     </errors> 
    </specialSources> 
</loggingConfiguration> 

Répondre

0

jamais l'esprit. J'ai finalement trouvé le problème. Mon mode Console a démarré le code réel, alors qu'en mode service mon code n'a pas été invoqué - donc pas de journalisation :).