I am trying to create a simple file logger for my windows service, but the file isn't being written to. Here is my app.config file:
<?xml version="1.0"?>
<configuration>
<configSections>
<section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, log4net" />
</configSections>
<connectionStrings>
<add name="MyAppConnectionString" connectionString="Data Source=.;Initial Catalog=MyApp;Integrated Security=True;MultipleActiveResultSets=True" />
<add name="MyAppEntities" connectionString="metadata=res://*/MyAppModel.csdl|res://*/MyAppModel.ssdl|res://*/MyAppModel.msl;provider=System.Data.SqlClient;provider connection string="Data Source=.;Initial Catalog=MyApp;Integrated Security=True;MultipleActiveResultSets=True"" providerName="System.Data.EntityClient" />
</connectionStrings>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/>
</startup>
<system.web>
<roleManager enabled="true" defaultProvider="MyAppSqlRoleProvider">
<providers>
<add name="MyAppSqlRoleProvider"
type="System.Web.Security.SqlRoleProvider"
applicationName="MyApp"
connectionStringName="MyAppConnectionString"/>
</providers>
</roleManager>
</system.web>
<log4net>
<appender name="FileAppender" type="log4net.Appender.FileAppender">
<file value="C:/logfiles/MyAppAlarms.txt" />
<appendToFile value="true" />
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%date [%thread] %-5level %message%newline" />
</layout>
</appender>
<root>
<level value="ALL" />
<appender-ref ref="FileAppender" />
</root>
</log4net>
</configuration>
I know there are other posts similar to this one, but I've read them and tried seemingly everything in them and I wasn't able to get anywhere. I tried putting the same tag above in a console app and that worked. I tried copying and pasting my app.config to the C:\ drive and referencing it using this in my AssemblyInfo.cs:
[assembly: log4net.Config.XmlConfigurator(Watch = true, ConfigFile = @"C:\app.config")]
but that did not work. I was able to attach to the service using a debugger, but I'm not sure how I can use that to my advantage here. Nothing is throwing an exception. I tried writing to the same file using a StreamWriter and that worked, so I know it's not a write-permissions issue.
I'm at a loss for what to try next. Is there a way I can get some debug info so I can figure out what is wrong? I tried enabling internal debugging and running DebugView, but I wasn't seeing anything except low-level networking messages. I also tried setting log4net debug=true, but I think this writes to the console which doesn't help in a service.