I am able to configure log4net instead of system trace. Posting the details here. may be helpful for others. --------------------------------------------------------------------------------------------------------------- --------------------------------------------------------------------------------------------------------------- web.config -------------- <system.diagnostics> <sources> <source name="ComponentSpace.SAML2" switchValue="Verbose"> <listeners> <add name="ComponentSpace" /> </listeners> </source> </sources> <sharedListeners> <add name="ComponentSpace" type="MyApp.Helper.Log4netTraceListener, MyApp" /> <!--this is the class namespace and the referral assembly name--> </sharedListeners> </system.diagnostics>
<log4net> <root> <level value="ALL" /> <appender-ref ref="RollingFileAppender" /> </root> <appender name="RollingFileAppender" type="log4net.Appender.RollingFileAppender"> <file value="Logs\rolling.log" /> <appendToFile value="true" /> <rollingStyle value="Size" /> <maxSizeRollBackups value="2" /> <maximumFileSize value="5KB" /> <staticLogFileName value="true" /> <layout type="log4net.Layout.PatternLayout"> <conversionPattern value="%date{dd/MMM/yyyy HH:mm:ss tt} [%thread] - %message%newline" /> </layout> </appender> </log4net>
Custom listener class override ---------------------------------------------- namespace MyApp.Helper { public class Log4netTraceListener : TraceListener { private readonly ILog _logManager;
public Log4netTraceListener() : this("System.Diagnostics.Redirection") {
}
public Log4netTraceListener(string name) : base(name) { _logManager = LogManager.GetLogger(name); }
public override void Write(string message) { if (_logManager != null) { _logManager.Debug(message); } }
public override void WriteLine(string message) { if (_logManager != null) { _logManager.Debug(message); } }
public override void TraceEvent(TraceEventCache eventCache, string source, TraceEventType eventType, int id) { TraceEvent(eventCache, source, eventType, id, string.Empty, new object[0]); }
public override void TraceEvent(TraceEventCache eventCache, string source, TraceEventType eventType, int id, string message) { TraceEvent(eventCache, source, eventType, id, message, new object[0]); } //And other overrides if needed...... } }
Global.asax --------------- Add the listener in application start
protected void Application_Start() { Trace.Listeners.Add(new Log4netTraceListener()); }
Thanks, MG
|