1. Download log4net from http://logging.apache.org/log4net/download.html
2. In the integration project, make a reference to the appropriate .NET level .dll in the downloaded .zip file – log4net.dll
3. In the Integration class, add:
private static log4net.ILog log; static MyIntegration() { log4net.Config.XmlConfigurator.Configure(); log = log4net.LogManager.GetLogger("SCORM Engine"); }
then the following overrides:
/// <summary> /// See <see cref="IntegrationInterface.LogAudit"/> for a full description. This implementation writes information to the ASP.NET Trace if it is available. /// </summary> /// <param name="logEntry">The value to be recorded.</param> /// <param name="externalConfig">External configuration information.</param> public override void LogAudit(string logEntry, ExternalConfiguration externalConfig) { string configSetting = GetConfigurationSetting(Constants.CONFIG_KEEP_AUDIT_LOG); if (CommonFunctions.ConvertStringToBoolean(configSetting)) { log.Info(logEntry); } } /// <summary> /// See <see cref="IntegrationInterface.LogDetail"/> for a full description. This implementation writes information to the ASP.NET Trace if it is available. /// </summary> /// <param name="logEntry">The value to be recorded.</param> /// <param name="externalConfig">External configuration information.</param> public override void LogDetail(string logEntry, ExternalConfiguration externalConfig) { string configSetting = GetConfigurationSetting(Constants.CONFIG_KEEP_DETAIL_LOG); if (CommonFunctions.ConvertStringToBoolean(configSetting)) { log.Debug(logEntry); } } /// <summary> /// See <see cref="IntegrationInterface.LogError"/> for a full description. This implementation writes information to the ASP.NET Trace if it is available. /// </summary> /// <param name="message">The value to be recorded.</param> /// <param name="exception">The exception that occurred.</param> public override void LogError(string message, Exception exception) { log.Error(message, exception); }
4. If the integration class is being COPIED rather than used as a project reference, you'll also need to copy the log4net.dll to the required webapps in a post-build event. The simplest thing to do is to just make sure the SCORM Engine Web (or Central and Remote) web applications have a direct reference to the Integration project.
5. Now, to log to a file you need to configure a listener via the web.config file. You can't use the SCORMEngineSettings.config file so will need to put this code in all web application web.config files where you want to record logging.
<configuration> <configSections> <section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler,Log4net"/> ...
and after the <appSettings> element put:
<appSettings> ... </appSettings> <log4net> <root> <level value="INFO" /> <appender-ref ref="LogFileAppender" /> </root> <appender name="LogFileAppender" type="log4net.Appender.RollingFileAppender" > <param name="File" value="C:\\logs\\scormengine.txt" /> <param name="AppendToFile" value="true" /> <rollingStyle value="Size" /> <maxSizeRollBackups value="10" /> <maximumFileSize value="10MB" /> <staticLogFileName value="true" /> <layout type="log4net.Layout.PatternLayout"> <param name="ConversionPattern" value="%-5p %d{yyyy-MM-dd hh:mm:ss} - %m%n" /> </layout> </appender> </log4net>
Note that this will give you 100 MB of logging (10MB files with 10 backups). Other appenders can be used, but this is the most common rolling file logger.