Windowsサービスでlog4netを使うための覚え書き

最近作っていたWindowsアプリをWindowsサービスに作り替えてみたら、log4netで出力していたイベントログが出力されなくなってしまった。最初は権限関係だろうと思っていろいろ試してみたがさっぱり解決できなくて、1週間くらい無駄にしてしまった。
原因はアプリケーション構成ファイルのパスが取得できなかったせい。プログラムフォルダのパスを取得するためにAssembly.GetCallingAssembly/GetExecutingAssemblyを使うと、「C:\Windows\System32」になり、実際のパスが取得できない(Windowsサービス特有か?)。System.Windows.Forms.Application.ExecutablePathなど、他の手段でも取得できなかった。
Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.Info.DirectoryPathはなぜか取得できるので、ほかの手段が見つかるまではMicrosoft.VisualBasicを参照に追加することにした。

string exename = Assembly.GetExecutingAssembly().GetName().Name + ".exe.config";
Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase MyApp
 = new Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase();
string configPath = Path.Combine(MyApp.Info.DirectoryPath, exename);

FileInfo info = new FileInfo(configPath);
log4net.Config.XmlConfigurator.Configure(log4net.LogManager.GetRepository(),
info);
20080508追記
AppDomain.CurrentDomain.SetupInformation.ConfigurationFileっていうのがあるのを最近知った。これで問題ないみたい。
FileInfo info = new FileInfo(AppDomain.CurrentDomain.SetupInformation.ConfigurationFile);
log4net.Config.XmlConfigurator.Configure(log4net.LogManager.GetRepository(), info);