0

I have created a windows service and i want windows service to log information into log file created under my user profile.I'm using common.logging and in the configuration i have specified my log config as below.

<configSections>
    <section name="quartz" type="System.Configuration.NameValueSectionHandler, System, Version=1.0.5000.0,Culture=neutral, PublicKeyToken=b77a5c561934e089" />
    <section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, log4net" />
    <sectionGroup name="common">
      <section name="logging" type="Common.Logging.ConfigurationSectionHandler, Common.Logging" />
    </sectionGroup>
  </configSections>

  <common>
    <logging>
      <factoryAdapter type="Common.Logging.Log4Net.Log4NetLoggerFactoryAdapter, Common.Logging.Log4net1213">
        <arg key="configType" value="INLINE" />
      </factoryAdapter>
    </logging>
  </common>

  <log4net>
    <appender name="ConsoleAppender" type="log4net.Appender.ConsoleAppender">
      <layout type="log4net.Layout.PatternLayout">
        <conversionPattern value="%d [%t] %-5p %l - %m%n" />
      </layout>
    </appender>
    <appender name="EventLogAppender" type="log4net.Appender.EventLogAppender">
      <layout type="log4net.Layout.PatternLayout">
        <conversionPattern value="%d [%t] %-5p %l - %m%n" />
      </layout>
    </appender>
    <appender name="FileAppender" type="log4net.Appender.FileAppender,log4net">
      <file value="${USERPROFILE}\Logs\Log.txt"/>
      <appendToFile value="true"/>
      <lockingModel type="log4net.Appender.FileAppender+MinimalLock"/>
      <layout type="log4net.Layout.PatternLayout">
        <conversionPattern value="%date [%thread] %level %logger - %message%newline"/>
      </layout>
      <filter type="log4net.Filter.LevelRangeFilter">
        <levelMin value="DEBUG"/>
        <levelMax value="FATAL"/>
      </filter>
    </appender>
    <root>
      <level value="ALL" />
      <appender-ref ref="FileAppender" />      
      <appender-ref ref="EventLogAppender" />
    </root>
  </log4net> 

But the windows service is not logging into the log file created under user profile. Service runs under Local System Account.I would like to get lead on the issue.event logs are working fine only the file appender is not working.

Rowland Shaw
  • 37,700
  • 14
  • 97
  • 166
pubudut
  • 603
  • 2
  • 8
  • 18

1 Answers1

0

The service is logged into the system account as you said that is a different user profile with a different path to the special folder. The simplest way to handle this is to put a symlink from your folder to the admin folder. You can do that with mklink.

rerun
  • 25,014
  • 6
  • 48
  • 78
  • I think your correct I missed something very obvious about user profiles logs are created under Local System Account User profile.Thanks for your comment you made my day mklink is kind a risky because I need to create installer for this tool and mklink will be a problem for end users so need to find work around create logs in a place where services and users both can access – pubudut Jan 30 '15 at 07:07
  • mklink is available on all windows systems as its built into CMD. As long as you have read access to the root log you will be able to run mklink. Also since you are using log4net you could also set up a network listener and have the user run that under their profile to collect logs. – rerun Jan 30 '15 at 15:16