我有一个使用ELAB作为日志记录的Windows服务。在控制台模式下运行服务时,所有日志记录都可以。但是一旦我作为服务启动它就不会发生日志记录。
我检查过的事情:
我不知道为什么这不起作用。
初始化日志记录:
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);
}
我的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 & Warnings">
<listeners>
<add name="Logfile" />
<add name="Console" />
</listeners>
</errors>
</specialSources>
</loggingConfiguration>
答案 0 :(得分:0)