У меня есть служба Windows, которая использует ELAB для ведения журнала. При запуске службы в режиме консоли вся регистрация работает нормально. Но как только я запускаю его как службу, никаких протоколов не происходит.EntLib V6 Регистрация в службе Windows
Вещи, которые я проверил:
- проверил разрешение папки и
- побежал на службу в консольном режиме от пользователя, который используется службой
- используется ProcMon, чтобы проверить, была даже попытка создать логфайл
- используется абсолютный и относительный путь, чтобы указать лог-файл
Я понятия не имею, почему это не работает.
Для инициализации протоколирования:
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);
}
И моя конфигурация Елаба:
<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 & Warnings">
<listeners>
<add name="Logfile" />
<add name="Console" />
</listeners>
</errors>
</specialSources>
</loggingConfiguration>