Index: log4net.build =================================================================== --- log4net.build (revision 344317) +++ log4net.build (working copy) @@ -397,6 +397,7 @@ + Index: src/Appender/EventLogAppender.cs =================================================================== --- src/Appender/EventLogAppender.cs (revision 344317) +++ src/Appender/EventLogAppender.cs (working copy) @@ -91,6 +91,10 @@ m_applicationName = System.Threading.Thread.GetDomain().FriendlyName; m_logName = "Application"; // Defaults to application log m_machineName = "."; // Only log on the local machine +#if (NET_2_0) + // .NET 2.0: Initialize EventSourceCreationData object + m_sourceData = new EventSourceCreationData(m_applicationName, m_logName); +#endif } /// @@ -134,7 +138,13 @@ public string LogName { get { return m_logName; } - set { m_logName = value; } + set + { + m_logName = value; +#if (NET_2_0) + m_sourceData.LogName = value; +#endif + } } /// @@ -150,7 +160,13 @@ public string ApplicationName { get { return m_applicationName; } - set { m_applicationName = value; } + set + { + m_applicationName = value; +#if (NET_2_0) + m_sourceData.Source = value; +#endif + } } /// @@ -271,13 +287,21 @@ // the application / logfile association // EventLog.DeleteEventSource(m_applicationName, m_machineName); +#if (NET_2_0) + EventLog.CreateEventSource(m_sourceData); +#else EventLog.CreateEventSource(m_applicationName, m_logName, m_machineName); +#endif registeredLogName = EventLog.LogNameFromSourceName(m_applicationName, m_machineName); } else if (!sourceAlreadyExists) { +#if (NET_2_0) + EventLog.CreateEventSource(m_sourceData); +#else EventLog.CreateEventSource(m_applicationName, m_logName, m_machineName); +#endif registeredLogName = EventLog.LogNameFromSourceName(m_applicationName, m_machineName); } @@ -441,7 +465,14 @@ /// private string m_machineName; +#if (NET_2_0) /// + /// EventSourceCreationData object for .NET 2.0 compatibility. + /// + private EventSourceCreationData m_sourceData; +#endif + + /// /// Mapping from level object to EventLogEntryType /// private LevelMapping m_levelMapping = new LevelMapping(); Index: src/Appender/SmtpAppender.cs =================================================================== --- src/Appender/SmtpAppender.cs (revision 344317) +++ src/Appender/SmtpAppender.cs (working copy) @@ -22,7 +22,14 @@ using System; using System.IO; + +// .NET 2.0: The System.Web.Mail namespace is deprecated. It is +// recommended to use System.Net.Mail namespace instead. +#if (NET_2_0) +using System.Net.Mail; +#else using System.Web.Mail; +#endif using log4net.Layout; using log4net.Core; @@ -275,6 +282,11 @@ /// The logging events to send. override protected void SendBuffer(LoggingEvent[] events) { + +#if (NET_2_0) + SmtpClient smtpClient; +#endif + // Note: this code already owns the monitor for this // appender. This frees us from needing to synchronize again. try @@ -301,8 +313,16 @@ MailMessage mailMessage = new MailMessage(); mailMessage.Body = writer.ToString(); +#if (NET_2_0) + // System.Net.Mail.MailMessage uses MailAddress instances + // instead of strings for addresses (and the To property + // is now a collection). + mailMessage.From = new MailAddress(m_from); + mailMessage.To.Add(new MailAddress(m_to)); +#else mailMessage.From = m_from; mailMessage.To = m_to; +#endif mailMessage.Subject = m_subject; mailMessage.Priority = m_mailPriority; @@ -353,13 +373,28 @@ ErrorHandler.Error("SmtpAppender: Server Port is only supported on the MS .NET 1.1 build of log4net"); } #endif - if (m_smtpHost != null && m_smtpHost.Length > 0) { + // .NET 2.0: warning CS0618: 'System.Web.Mail.SmtpMail' is obsolete: + // 'The recommended alternative is System.Net.Mail.SmtpClient. http://go.microsoft.com/fwlink/?linkid=14202' +#if (NET_2_0) + smtpClient = new SmtpClient(m_smtpHost); +#else SmtpMail.SmtpServer = m_smtpHost; +#endif } + // .NET 2.0: warning CS0618: 'System.Web.Mail.SmtpMail' is obsolete: + // 'The recommended alternative is System.Net.Mail.SmtpClient. http://go.microsoft.com/fwlink/?linkid=14202' +#if (NET_2_0) + else + { + smtpClient = new SmtpClient(); + } + smtpClient.Send(mailMessage); +#else SmtpMail.Send(mailMessage); +#endif } catch(Exception e) { @@ -444,4 +479,4 @@ } } -#endif // !NETCF && !SSCLI \ No newline at end of file +#endif // !NETCF && !SSCLI Index: src/Config/XmlConfigurator.cs =================================================================== --- src/Config/XmlConfigurator.cs (revision 344317) +++ src/Config/XmlConfigurator.cs (working copy) @@ -153,7 +153,14 @@ #else try { +#if (NET_2_0) + // warning CS0618: 'System.Configuration.ConfigurationSettings.GetConfig(string)' is obsolete: + // 'This method is obsolete, it has been replaced by + // System.Configuration!System.Configuration.ConfigurationManager.GetSection + XmlElement configElement = System.Configuration.ConfigurationManager.GetSection("log4net") as XmlElement; +#else XmlElement configElement = System.Configuration.ConfigurationSettings.GetConfig("log4net") as XmlElement; +#endif if (configElement == null) { // Failed to load the xml config using configuration settings handler @@ -615,13 +622,29 @@ XmlTextReader xmlReader = new XmlTextReader(configStream); #else // Create a validating reader around a text reader for the file stream + + // .NET 2.0: warning CS0618: 'System.Xml.XmlValidatingReader' is obsolete: + // 'Use XmlReader created by XmlReader.Create() method using appropriate + // XmlReaderSettings instead. http://go.microsoft.com/fwlink/?linkid=14202' +#if (NET_2_0) + XmlReaderSettings xmlReaderSettings = new XmlReaderSettings(); + + // Specify that the reader should not perform validation, but that it should + // expand entity refs. + // .NET 2.0: By default, XmlReaders created by XmlReaderSettings + // automatically expand refs. + xmlReaderSettings.ValidationType = ValidationType.None; + + XmlReader xmlReader = XmlReader.Create(configStream, xmlReaderSettings); +#else XmlValidatingReader xmlReader = new XmlValidatingReader(new XmlTextReader(configStream)); // Specify that the reader should not perform validation, but that it should // expand entity refs. xmlReader.ValidationType = ValidationType.None; xmlReader.EntityHandling = EntityHandling.ExpandEntities; -#endif +#endif // NET_2_0 +#endif // NETCF // load the data into the document doc.Load(xmlReader); Index: src/Core/DefaultRepositorySelector.cs =================================================================== --- src/Core/DefaultRepositorySelector.cs (revision 344317) +++ src/Core/DefaultRepositorySelector.cs (working copy) @@ -649,7 +649,11 @@ try { +#if (NET_2_0) + repositoryConfigFile = ConfigurationManager.AppSettings["log4net.Config"]; +#else repositoryConfigFile = ConfigurationSettings.AppSettings["log4net.Config"]; +#endif } catch(Exception ex) { Index: src/Core/LevelMap.cs =================================================================== --- src/Core/LevelMap.cs (revision 344317) +++ src/Core/LevelMap.cs (working copy) @@ -43,7 +43,15 @@ /// Mapping from level name to Level object. The /// level name is case insensitive /// + // .NET 2.0: warning CS0618: 'System.Collections.CaseInsensitiveHashCodeProvider' is obsolete: + // 'Please use StringComparer instead. + // .NET 2.0: warning CS0618: 'System.Collections.Hashtable.Hashtable(System.Collections.IHashCodeProvider, + // System.Collections.IComparer)' is obsolete: 'Please use Hashtable(IEqualityComparer) instead. +#if (NET_2_0) + private Hashtable m_mapName2Level = new Hashtable(StringComparer.InvariantCultureIgnoreCase); +#else private Hashtable m_mapName2Level = new Hashtable(CaseInsensitiveHashCodeProvider.Default, CaseInsensitiveComparer.Default); +#endif #endregion Index: src/Core/LoggerManager.cs =================================================================== --- src/Core/LoggerManager.cs (revision 344317) +++ src/Core/LoggerManager.cs (working copy) @@ -106,7 +106,14 @@ try { +#if (NET_2_0) + // 'System.Configuration.ConfigurationSettings.AppSettings' is obsolete: + // 'This method is obsolete, it has been replaced by + // System.Configuration!System.Configuration.ConfigurationManager.AppSettings + appRepositorySelectorTypeName = ConfigurationManager.AppSettings["log4net.RepositorySelector"]; +#else appRepositorySelectorTypeName = ConfigurationSettings.AppSettings["log4net.RepositorySelector"]; +#endif } catch(Exception ex) { Index: src/Layout/XMLLayout.cs =================================================================== --- src/Layout/XMLLayout.cs (revision 344317) +++ src/Layout/XMLLayout.cs (working copy) @@ -218,7 +218,15 @@ { writer.WriteStartElement(m_elmEvent); writer.WriteAttributeString(ATTR_LOGGER, loggingEvent.LoggerName); +#if (NET_2_0) + // warning CS0618: 'System.Xml.XmlConvert.ToString(System.DateTime)' is obsolete: + // 'Use XmlConvert.ToString() that takes in XmlDateTimeSerializationMode' + // HACK: See http://blogs.msdn.com/bclteam/archive/2005/03/07/387677.aspx - this is the closest + // behavioral match with what's in the nunit tests... + writer.WriteAttributeString(ATTR_TIMESTAMP, loggingEvent.TimeStamp.ToString("yyyy-MM-ddTHH:mm:ss.fffffff")); +#else writer.WriteAttributeString(ATTR_TIMESTAMP, XmlConvert.ToString(loggingEvent.TimeStamp)); +#endif writer.WriteAttributeString(ATTR_LEVEL, loggingEvent.Level.DisplayName); writer.WriteAttributeString(ATTR_THREAD, loggingEvent.ThreadName); Index: src/Repository/Hierarchy/XmlHierarchyConfigurator.cs =================================================================== --- src/Repository/Hierarchy/XmlHierarchyConfigurator.cs (revision 344317) +++ src/Repository/Hierarchy/XmlHierarchyConfigurator.cs (working copy) @@ -135,7 +135,7 @@ } } -#if (!NETCF) +#if (!NETCF && !NET_2_0) LogLog.Debug("XmlHierarchyConfigurator: Configuration update mode [" + configUpdateMode.ToString(CultureInfo.InvariantCulture) + "]."); #else LogLog.Debug("XmlHierarchyConfigurator: Configuration update mode [" + configUpdateMode.ToString() + "]."); Index: src/Util/LogLog.cs =================================================================== --- src/Util/LogLog.cs (revision 344317) +++ src/Util/LogLog.cs (working copy) @@ -81,9 +81,14 @@ #if !NETCF try { +#if (NET_2_0) + InternalDebugging = OptionConverter.ToBoolean(ConfigurationManager.AppSettings["log4net.Internal.Debug"], false); + QuietMode = OptionConverter.ToBoolean(ConfigurationManager.AppSettings["log4net.Internal.Quiet"], false); +#else InternalDebugging = OptionConverter.ToBoolean(ConfigurationSettings.AppSettings["log4net.Internal.Debug"], false); QuietMode = OptionConverter.ToBoolean(ConfigurationSettings.AppSettings["log4net.Internal.Quiet"], false); - } +#endif + } catch(Exception ex) { // If an exception is thrown here then it looks like the config file does not Index: src/Util/SystemInfo.cs =================================================================== --- src/Util/SystemInfo.cs (revision 344317) +++ src/Util/SystemInfo.cs (working copy) @@ -173,8 +173,17 @@ #if NETCF return System.Threading.Thread.CurrentThread.GetHashCode(); #else + // .NET 2.0: warning CS0618: 'System.AppDomain.GetCurrentThreadId()' is obsolete: + // 'AppDomain.GetCurrentThreadId has been deprecated because it does not provide a + // stable Id when managed threads are running on fibers (aka lightweight threads). + // To get a stable identifier for a managed thread, use the ManagedThreadId property + // on Thread. http://go.microsoft.com/fwlink/?linkid=14202' +#if (NET_2_0) + return System.Threading.Thread.CurrentThread.ManagedThreadId; +#else return AppDomain.GetCurrentThreadId(); -#endif +#endif // NET_2_0 +#endif // NETCF } } Index: src/Util/TypeConverters/IPAddressConverter.cs =================================================================== --- src/Util/TypeConverters/IPAddressConverter.cs (revision 344317) +++ src/Util/TypeConverters/IPAddressConverter.cs (working copy) @@ -91,7 +91,14 @@ } // Try to resolve via DNS. This is a blocking call. +#if (NET_2_0) + // 'System.Net.Dns.GetHostByName(string)' is obsolete: + // 'GetHostByName is obsoleted for this type, + // please use GetHostEntry instead. + IPHostEntry host = Dns.GetHostEntry(str); +#else IPHostEntry host = Dns.GetHostByName(str); +#endif if (host != null && host.AddressList != null && host.AddressList.Length > 0 && Index: tests/src/Appender/RemotingAppenderTest.cs =================================================================== --- tests/src/Appender/RemotingAppenderTest.cs (revision 344317) +++ tests/src/Appender/RemotingAppenderTest.cs (working copy) @@ -195,7 +195,11 @@ // Setup remoting server try { +#if (NET_2_0) + ChannelServices.RegisterChannel(m_remotingChannel, false); +#else ChannelServices.RegisterChannel(m_remotingChannel); +#endif } catch(Exception) {