解決策は次のとおりです。
public static class MyLogManager
{
public static ILog GetThreadAwareIPLogger(string loggerid)
{
if (log4net.ThreadContext.Properties["ip"] == null || !string.IsNullOrEmpty(log4net.ThreadContext.Properties["ip"].ToString()))
log4net.ThreadContext.Properties["ip"] = HttpContext.Current.Request.UserHostAddress.PadLeft(15);
return LogManager.GetLogger(loggerid);
}
}
これは解決策の始まりにすぎません。ポイントは、独自の public static クラス内で (そうでなければ) シールされたクラスを使用して、新しい Thread-Aware/Session-Aware Logger-factory を作成することです。
どのセッションから作成/生成されたかを認識し、新しいロガーを要求するとスレッドの ThreadContext に IP を自動的に設定する log4net ILog インスタンスを取得します。これが他の誰かに役立つことを願っています:-)