Logging Doesn't work when Application run as a service

Topics: Logging Application Block
Mar 9, 2012 at 6:28 AM

Hi, when I run the application in Console mode, the Logging function works well. However, when I run this application as a windows service, the logging doesn't work anymore. Does anyone know the reason? Thanks.

Mar 9, 2012 at 4:45 PM
Edited Mar 9, 2012 at 8:13 PM

It's hard to say what is going on without some more information.

What do you mean by the logging doesn't work: are you getting an error or are no log entries appearing?  What trace listener are you using (Flat File, Event Log, Database, etc.)? 

I would guess it's probably a permission issue but it's hard to say; console mode would be running as the interactive user while the service would be running under a service account.

--
Randy Levy
Enterprise Library support engineer
entlib.support@live.com 

Mar 12, 2012 at 2:46 AM
Edited Mar 12, 2012 at 2:50 AM
randylevy wrote:

It's hard to say what is going on without some more information.

What do you mean by the logging doesn't work: are you getting an error or are no log entries appearing?  What trace listener are you using (Flat File, Event Log, Database, etc.)? 

I would guess it's probably a permission issue but it's hard to say; console mode would be running as the interactive user while the service would be running under a service account.

--
Randy Levy
Enterprise Library support engineer
entlib.support@live.com 

Hi Randy,

For this application, we use File configuration source. When the application runs as a service, enterprise library will complain that the specified configuration file can't be found. When I change the file configuration source from relative file path to an absolute file path, the problem disappear. When the application runs as a console application, there is no problem at all. The app.config file looks like:

<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="File Configuration Source">   

<sources>      <add name="File Configuration Source" type="Microsoft.Practices.EnterpriseLibrary.Common.Configuration.FileConfigurationSource, Microsoft.Practices.EnterpriseLibrary.Common"        filePath="Logging.config" />      <add name="System Configuration Source" type="Microsoft.Practices.EnterpriseLibrary.Common.Configuration.SystemConfigurationSource, Microsoft.Practices.EnterpriseLibrary.Common" />    </sources> 

</enterpriseLibrary.ConfigurationSource>

 

Enterprise library will complain the file Logging.config can't be found. 

Do you know the reason? Thanks.

Mar 12, 2012 at 4:35 AM

Thanks for the information.  There is a bug in Enterprise Library 5 build 414 handling relative paths with FileConfigurationSource which is what you are running into.

The easiest fix is to upgrade to Enterprise Library 5 Optional Update 1.  Other fixes without upgrading are to create your own FileConfigurationSource or change the Environment.CurrentDirectory when configuring Enterprise Library.  Details can be found in the comments of the issue

--
Randy Levy
Enterprise Library support engineer
entlib.support@live.com