You are viewing a plain text version of this content. The canonical link for it is here.
Posted to log4net-dev@logging.apache.org by ni...@apache.org on 2006/02/17 20:20:26 UTC
svn commit: r378595 - in /logging/log4net/trunk: ./ src/Appender/
src/Config/ src/Core/ src/Repository/Hierarchy/ src/Util/
src/Util/TypeConverters/ tests/src/Appender/ tests/src/Layout/
Author: nicko
Date: Fri Feb 17 11:20:22 2006
New Revision: 378595
URL: http://svn.apache.org/viewcvs?rev=378595&view=rev
Log:
Fix for LOG4NET-58 Support clean build on .NET 2.0.
Updates to work around obsolete warning messages from the MS .NET 2.0 compiler.
Modified:
logging/log4net/trunk/log4net.build
logging/log4net/trunk/src/Appender/EventLogAppender.cs
logging/log4net/trunk/src/Appender/SmtpAppender.cs
logging/log4net/trunk/src/Config/XmlConfigurator.cs
logging/log4net/trunk/src/Core/DefaultRepositorySelector.cs
logging/log4net/trunk/src/Core/LevelMap.cs
logging/log4net/trunk/src/Core/LoggerManager.cs
logging/log4net/trunk/src/Repository/Hierarchy/XmlHierarchyConfigurator.cs
logging/log4net/trunk/src/Util/LogLog.cs
logging/log4net/trunk/src/Util/SystemInfo.cs
logging/log4net/trunk/src/Util/TypeConverters/IPAddressConverter.cs
logging/log4net/trunk/tests/src/Appender/RemotingAppenderTest.cs
logging/log4net/trunk/tests/src/Layout/XmlLayoutTest.cs
Modified: logging/log4net/trunk/log4net.build
URL: http://svn.apache.org/viewcvs/logging/log4net/trunk/log4net.build?rev=378595&r1=378594&r2=378595&view=diff
==============================================================================
--- logging/log4net/trunk/log4net.build (original)
+++ logging/log4net/trunk/log4net.build Fri Feb 17 11:20:22 2006
@@ -408,6 +408,7 @@
<include name="System.Data.dll" />
<include name="System.Web.dll" />
<include name="System.Xml.dll" />
+ <include name="System.Configuration.dll" />
<!-- allow for third party assemblies to be referenced by just storing them in the lib/<framework family>/<framework version>/<build configuration> directory -->
<include name="lib/${framework::get-family(framework::get-target-framework())}/${framework::get-version(framework::get-target-framework())}/${current.build.config}/*.dll" />
</references>
Modified: logging/log4net/trunk/src/Appender/EventLogAppender.cs
URL: http://svn.apache.org/viewcvs/logging/log4net/trunk/src/Appender/EventLogAppender.cs?rev=378595&r1=378594&r2=378595&view=diff
==============================================================================
--- logging/log4net/trunk/src/Appender/EventLogAppender.cs (original)
+++ logging/log4net/trunk/src/Appender/EventLogAppender.cs Fri Feb 17 11:20:22 2006
@@ -271,13 +271,13 @@
// the application / logfile association
//
EventLog.DeleteEventSource(m_applicationName, m_machineName);
- EventLog.CreateEventSource(m_applicationName, m_logName, m_machineName);
+ CreateEventSource(m_applicationName, m_logName, m_machineName);
registeredLogName = EventLog.LogNameFromSourceName(m_applicationName, m_machineName);
}
else if (!sourceAlreadyExists)
{
- EventLog.CreateEventSource(m_applicationName, m_logName, m_machineName);
+ CreateEventSource(m_applicationName, m_logName, m_machineName);
registeredLogName = EventLog.LogNameFromSourceName(m_applicationName, m_machineName);
}
@@ -289,6 +289,24 @@
}
#endregion // Implementation of IOptionHandler
+
+ /// <summary>
+ /// Create an event log source
+ /// </summary>
+ /// <remarks>
+ /// Uses different API calls under NET_2_0
+ /// </remarks>
+ private static void CreateEventSource(string source, string logName, string machineName)
+ {
+#if NET_2_0
+ EventSourceCreationData eventSourceCreationData = new EventSourceCreationData(source, logName);
+ eventSourceCreationData.MachineName = machineName;
+ EventLog.CreateEventSource(eventSourceCreationData);
+#else
+ EventLog.CreateEventSource(source, logName, machineName);
+#endif
+ }
+
#region Override implementation of AppenderSkeleton
Modified: logging/log4net/trunk/src/Appender/SmtpAppender.cs
URL: http://svn.apache.org/viewcvs/logging/log4net/trunk/src/Appender/SmtpAppender.cs?rev=378595&r1=378594&r2=378595&view=diff
==============================================================================
--- logging/log4net/trunk/src/Appender/SmtpAppender.cs (original)
+++ logging/log4net/trunk/src/Appender/SmtpAppender.cs Fri Feb 17 11:20:22 2006
@@ -22,7 +22,12 @@
using System;
using System.IO;
+
+#if NET_2_0
+using System.Net.Mail;
+#else
using System.Web.Mail;
+#endif
using log4net.Layout;
using log4net.Core;
@@ -299,6 +304,44 @@
writer.Write(t);
}
+#if NET_2_0
+ // .NET 2.0 has a new API for SMTP email System.Net.Mail
+ // This API supports credentials and multiple hosts correctly.
+ // The old API is deprecated.
+
+ // Create and configure the smtp client
+ SmtpClient smtpClient = new SmtpClient();
+ if (m_smtpHost != null && m_smtpHost.Length > 0)
+ {
+ smtpClient.Host = m_smtpHost;
+ }
+ smtpClient.Port = m_port;
+ smtpClient.DeliveryMethod = SmtpDeliveryMethod.Network;
+
+ if (m_authentication == SmtpAuthentication.Basic)
+ {
+ // Perform basic authentication
+ smtpClient.Credentials = new System.Net.NetworkCredential(m_username, m_password);
+ }
+ else if (m_authentication == SmtpAuthentication.Ntlm)
+ {
+ // Perform integrated authentication (NTLM)
+ smtpClient.Credentials = System.Net.CredentialCache.DefaultNetworkCredentials;
+ }
+
+ MailMessage mailMessage = new MailMessage();
+ mailMessage.Body = writer.ToString();
+ mailMessage.From = new MailAddress(m_from);
+ mailMessage.To.Add(m_to);
+ mailMessage.Subject = m_subject;
+ mailMessage.Priority = m_mailPriority;
+
+ // TODO: Consider using SendAsync to send the message without blocking. This would be a change in
+ // behaviour compared to .NET 1.x. We would need a SendCompletedCallback to log errors.
+ smtpClient.Send(mailMessage);
+#else
+ // .NET 1.x uses the System.Web.Mail API for sending Mail
+
MailMessage mailMessage = new MailMessage();
mailMessage.Body = writer.ToString();
mailMessage.From = m_from;
@@ -345,14 +388,14 @@
#else
if (m_authentication != SmtpAuthentication.None)
{
- ErrorHandler.Error("SmtpAppender: Authentication is only supported on the MS .NET 1.1 build of log4net");
+ ErrorHandler.Error("SmtpAppender: Authentication is only supported on the MS .NET 1.1 or MS .NET 2.0 builds of log4net");
}
if (m_port != 25)
{
- ErrorHandler.Error("SmtpAppender: Server Port is only supported on the MS .NET 1.1 build of log4net");
+ ErrorHandler.Error("SmtpAppender: Server Port is only supported on the MS .NET 1.1 or MS .NET 2.0 builds of log4net");
}
-#endif
+#endif // if NET_1_1
if (m_smtpHost != null && m_smtpHost.Length > 0)
{
@@ -360,6 +403,7 @@
}
SmtpMail.Send(mailMessage);
+#endif // if NET_2_0
}
catch(Exception e)
{
Modified: logging/log4net/trunk/src/Config/XmlConfigurator.cs
URL: http://svn.apache.org/viewcvs/logging/log4net/trunk/src/Config/XmlConfigurator.cs?rev=378595&r1=378594&r2=378595&view=diff
==============================================================================
--- logging/log4net/trunk/src/Config/XmlConfigurator.cs (original)
+++ logging/log4net/trunk/src/Config/XmlConfigurator.cs Fri Feb 17 11:20:22 2006
@@ -153,7 +153,12 @@
#else
try
{
- XmlElement configElement = System.Configuration.ConfigurationSettings.GetConfig("log4net") as XmlElement;
+ XmlElement configElement = null;
+#if NET_2_0
+ configElement = System.Configuration.ConfigurationManager.GetSection("log4net") as XmlElement;
+#else
+ configElement = System.Configuration.ConfigurationSettings.GetConfig("log4net") as XmlElement;
+#endif
if (configElement == null)
{
// Failed to load the xml config using configuration settings handler
@@ -613,6 +618,13 @@
#if (NETCF)
// Create a text reader for the file stream
XmlTextReader xmlReader = new XmlTextReader(configStream);
+#elif NET_2_0
+ // Allow the DTD to specify entity includes
+ XmlReaderSettings settings = new XmlReaderSettings();
+ settings.ProhibitDtd = false;
+
+ // Create a reader over the input stream
+ XmlReader xmlReader = XmlReader.Create(configStream, settings);
#else
// Create a validating reader around a text reader for the file stream
XmlValidatingReader xmlReader = new XmlValidatingReader(new XmlTextReader(configStream));
Modified: logging/log4net/trunk/src/Core/DefaultRepositorySelector.cs
URL: http://svn.apache.org/viewcvs/logging/log4net/trunk/src/Core/DefaultRepositorySelector.cs?rev=378595&r1=378594&r2=378595&view=diff
==============================================================================
--- logging/log4net/trunk/src/Core/DefaultRepositorySelector.cs (original)
+++ logging/log4net/trunk/src/Core/DefaultRepositorySelector.cs Fri Feb 17 11:20:22 2006
@@ -645,18 +645,7 @@
// Do this even if the repository has been configured (or claims to be), this allows overriding
// of the default config files etc, if that is required.
- string repositoryConfigFile = null;
-
- try
- {
- repositoryConfigFile = ConfigurationSettings.AppSettings["log4net.Config"];
- }
- catch(Exception ex)
- {
- // If an exception is thrown here then it looks like the config file does not parse correctly.
- LogLog.Error("DefaultRepositorySelector: Exception while reading ConfigurationSettings. Check your .config file is well formed XML.", ex);
- }
-
+ string repositoryConfigFile = SystemInfo.GetAppSetting("log4net.Config");
if (repositoryConfigFile != null && repositoryConfigFile.Length > 0)
{
// Resolve the config path relative to the application base directory URI
Modified: logging/log4net/trunk/src/Core/LevelMap.cs
URL: http://svn.apache.org/viewcvs/logging/log4net/trunk/src/Core/LevelMap.cs?rev=378595&r1=378594&r2=378595&view=diff
==============================================================================
--- logging/log4net/trunk/src/Core/LevelMap.cs (original)
+++ logging/log4net/trunk/src/Core/LevelMap.cs Fri Feb 17 11:20:22 2006
@@ -43,7 +43,7 @@
/// Mapping from level name to Level object. The
/// level name is case insensitive
/// </summary>
- private Hashtable m_mapName2Level = new Hashtable(CaseInsensitiveHashCodeProvider.Default, CaseInsensitiveComparer.Default);
+ private Hashtable m_mapName2Level = SystemInfo.CreateCaseInsensitiveHashtable();
#endregion
Modified: logging/log4net/trunk/src/Core/LoggerManager.cs
URL: http://svn.apache.org/viewcvs/logging/log4net/trunk/src/Core/LoggerManager.cs?rev=378595&r1=378594&r2=378595&view=diff
==============================================================================
--- logging/log4net/trunk/src/Core/LoggerManager.cs (original)
+++ logging/log4net/trunk/src/Core/LoggerManager.cs Fri Feb 17 11:20:22 2006
@@ -102,18 +102,7 @@
#else
// Look for the RepositorySelector type specified in the AppSettings 'log4net.RepositorySelector'
- string appRepositorySelectorTypeName = null;
-
- try
- {
- appRepositorySelectorTypeName = ConfigurationSettings.AppSettings["log4net.RepositorySelector"];
- }
- catch(Exception ex)
- {
- // If an exception is thrown here then it looks like the config file does not parse correctly.
- LogLog.Error("LoggerManager: Exception while reading ConfigurationSettings. Check your .config file is well formed XML.", ex);
- }
-
+ string appRepositorySelectorTypeName = SystemInfo.GetAppSetting("log4net.RepositorySelector");
if (appRepositorySelectorTypeName != null && appRepositorySelectorTypeName.Length > 0)
{
// Resolve the config string into a Type
Modified: logging/log4net/trunk/src/Repository/Hierarchy/XmlHierarchyConfigurator.cs
URL: http://svn.apache.org/viewcvs/logging/log4net/trunk/src/Repository/Hierarchy/XmlHierarchyConfigurator.cs?rev=378595&r1=378594&r2=378595&view=diff
==============================================================================
--- logging/log4net/trunk/src/Repository/Hierarchy/XmlHierarchyConfigurator.cs (original)
+++ logging/log4net/trunk/src/Repository/Hierarchy/XmlHierarchyConfigurator.cs Fri Feb 17 11:20:22 2006
@@ -135,11 +135,8 @@
}
}
-#if (!NETCF)
- LogLog.Debug("XmlHierarchyConfigurator: Configuration update mode [" + configUpdateMode.ToString(CultureInfo.InvariantCulture) + "].");
-#else
+ // IMPL: The IFormatProvider argument to Enum.ToString() is deprecated in .NET 2.0
LogLog.Debug("XmlHierarchyConfigurator: Configuration update mode [" + configUpdateMode.ToString() + "].");
-#endif
// Only reset configuration if overwrite flag specified
if (configUpdateMode == ConfigUpdateMode.Overwrite)
Modified: logging/log4net/trunk/src/Util/LogLog.cs
URL: http://svn.apache.org/viewcvs/logging/log4net/trunk/src/Util/LogLog.cs?rev=378595&r1=378594&r2=378595&view=diff
==============================================================================
--- logging/log4net/trunk/src/Util/LogLog.cs (original)
+++ logging/log4net/trunk/src/Util/LogLog.cs Fri Feb 17 11:20:22 2006
@@ -81,8 +81,8 @@
#if !NETCF
try
{
- InternalDebugging = OptionConverter.ToBoolean(ConfigurationSettings.AppSettings["log4net.Internal.Debug"], false);
- QuietMode = OptionConverter.ToBoolean(ConfigurationSettings.AppSettings["log4net.Internal.Quiet"], false);
+ InternalDebugging = OptionConverter.ToBoolean(SystemInfo.GetAppSetting("log4net.Internal.Debug"), false);
+ QuietMode = OptionConverter.ToBoolean(SystemInfo.GetAppSetting("log4net.Internal.Quiet"), false);
}
catch(Exception ex)
{
Modified: logging/log4net/trunk/src/Util/SystemInfo.cs
URL: http://svn.apache.org/viewcvs/logging/log4net/trunk/src/Util/SystemInfo.cs?rev=378595&r1=378594&r2=378595&view=diff
==============================================================================
--- logging/log4net/trunk/src/Util/SystemInfo.cs (original)
+++ logging/log4net/trunk/src/Util/SystemInfo.cs Fri Feb 17 11:20:22 2006
@@ -22,6 +22,7 @@
using System.Text;
using System.IO;
using System.Runtime.InteropServices;
+using System.Collections;
namespace log4net.Util
{
@@ -78,7 +79,7 @@
#if !NETCF
// Look for log4net.NullText in AppSettings
- string nullTextAppSettingsKey = ConfigurationSettings.AppSettings["log4net.NullText"];
+ string nullTextAppSettingsKey = SystemInfo.GetAppSetting("log4net.NullText");
if (nullTextAppSettingsKey != null && nullTextAppSettingsKey.Length > 0)
{
LogLog.Debug("SystemInfo: Initializing NullText value to [" + nullTextAppSettingsKey + "].");
@@ -86,7 +87,7 @@
}
// Look for log4net.NotAvailableText in AppSettings
- string notAvailableTextAppSettingsKey = ConfigurationSettings.AppSettings["log4net.NotAvailableText"];
+ string notAvailableTextAppSettingsKey = SystemInfo.GetAppSetting("log4net.NotAvailableText");
if (notAvailableTextAppSettingsKey != null && notAvailableTextAppSettingsKey.Length > 0)
{
LogLog.Debug("SystemInfo: Initializing NotAvailableText value to [" + notAvailableTextAppSettingsKey + "].");
@@ -211,6 +212,11 @@
/// <c>GetCurrentThreadId</c> is implemented inline in a header file
/// and cannot be called.
/// </para>
+ /// <para>
+ /// On the .NET Framework 2.0 the <c>Thread.ManagedThreadId</c> is used as this
+ /// gives a stable id unrelated to the operating system thread ID which may
+ /// change if the runtime is using fibers.
+ /// </para>
/// </remarks>
public static int CurrentThreadId
{
@@ -218,6 +224,8 @@
{
#if NETCF
return System.Threading.Thread.CurrentThread.GetHashCode();
+#elif NET_2_0
+ return System.Threading.Thread.CurrentThread.ManagedThreadId;
#else
return AppDomain.GetCurrentThreadId();
#endif
@@ -812,6 +820,36 @@
}
/// <summary>
+ /// Lookup an application setting
+ /// </summary>
+ /// <param name="key">the application settings key to lookup</param>
+ /// <returns>the value for the key, or <c>null</c></returns>
+ /// <remarks>
+ /// <para>
+ /// Configuration APIs are not suported under the Compact Framework
+ /// </para>
+ /// </remarks>
+ public static string GetAppSetting(string key)
+ {
+ try
+ {
+#if NETCF
+ // Configuration APIs are not suported under the Compact Framework
+#elif NET_2_0
+ return ConfigurationManager.AppSettings[key];
+#else
+ return ConfigurationSettings.AppSettings[key];
+#endif
+ }
+ catch(Exception ex)
+ {
+ // If an exception is thrown here then it looks like the config file does not parse correctly.
+ LogLog.Error("DefaultRepositorySelector: Exception while reading ConfigurationSettings. Check your .config file is well formed XML.", ex);
+ }
+ return null;
+ }
+
+ /// <summary>
/// Convert a path into a fully qualified local file path.
/// </summary>
/// <param name="path">The path to convert.</param>
@@ -859,6 +897,24 @@
return Path.GetFullPath(Path.Combine(baseDirectory, path));
}
return Path.GetFullPath(path);
+ }
+
+ /// <summary>
+ /// Creates a new case-insensitive instance of the <see cref="Hashtable"/> class with the default initial capacity.
+ /// </summary>
+ /// <returns>A new case-insensitive instance of the <see cref="Hashtable"/> class with the default initial capacity</returns>
+ /// <remarks>
+ /// <para>
+ /// The new Hashtable instance uses the default load factor, the CaseInsensitiveHashCodeProvider, and the CaseInsensitiveComparer.
+ /// </para>
+ /// </remarks>
+ public static Hashtable CreateCaseInsensitiveHashtable()
+ {
+#if NETCF
+ return new Hashtable(CaseInsensitiveHashCodeProvider.Default, CaseInsensitiveComparer.Default);
+#else
+ return System.Collections.Specialized.CollectionsUtil.CreateCaseInsensitiveHashtable();
+#endif
}
#endregion Public Static Methods
Modified: logging/log4net/trunk/src/Util/TypeConverters/IPAddressConverter.cs
URL: http://svn.apache.org/viewcvs/logging/log4net/trunk/src/Util/TypeConverters/IPAddressConverter.cs?rev=378595&r1=378594&r2=378595&view=diff
==============================================================================
--- logging/log4net/trunk/src/Util/TypeConverters/IPAddressConverter.cs (original)
+++ logging/log4net/trunk/src/Util/TypeConverters/IPAddressConverter.cs Fri Feb 17 11:20:22 2006
@@ -76,6 +76,20 @@
{
try
{
+#if NET_2_0
+ // Try to resolve via DNS. This is a blocking call.
+ // GetHostEntry works with either an IPAddress string or a host name
+ IPHostEntry host = Dns.GetHostEntry(str);
+ if (host != null &&
+ host.AddressList != null &&
+ host.AddressList.Length > 0 &&
+ host.AddressList[0] != null)
+ {
+ return host.AddressList[0];
+ }
+#else
+ // Before .NET 2 we need to try to parse the IPAddress from the string first
+
// Check if the string only contains IP address valid chars
if (str.Trim(validIpAddressChars).Length == 0)
{
@@ -99,6 +113,7 @@
{
return host.AddressList[0];
}
+#endif
}
catch(Exception ex)
{
Modified: logging/log4net/trunk/tests/src/Appender/RemotingAppenderTest.cs
URL: http://svn.apache.org/viewcvs/logging/log4net/trunk/tests/src/Appender/RemotingAppenderTest.cs?rev=378595&r1=378594&r2=378595&view=diff
==============================================================================
--- logging/log4net/trunk/tests/src/Appender/RemotingAppenderTest.cs (original)
+++ logging/log4net/trunk/tests/src/Appender/RemotingAppenderTest.cs Fri Feb 17 11:20:22 2006
@@ -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)
{
Modified: logging/log4net/trunk/tests/src/Layout/XmlLayoutTest.cs
URL: http://svn.apache.org/viewcvs/logging/log4net/trunk/tests/src/Layout/XmlLayoutTest.cs?rev=378595&r1=378594&r2=378595&view=diff
==============================================================================
--- logging/log4net/trunk/tests/src/Layout/XmlLayoutTest.cs (original)
+++ logging/log4net/trunk/tests/src/Layout/XmlLayoutTest.cs Fri Feb 17 11:20:22 2006
@@ -58,14 +58,14 @@
private string createEventNode(string message)
{
return String.Format("<event logger=\"TestLogger\" timestamp=\"{0}\" level=\"INFO\" thread=\"TestThread\" domain=\"Tests\" identity=\"TestRunner\" username=\"TestRunner\"><message>{1}</message></event>\r\n",
- XmlConvert.ToString(DateTime.Today),
+ XmlConvert.ToString(DateTime.Today, XmlDateTimeSerializationMode.Local),
message);
}
private string createEventNode(string key, string value)
{
return String.Format("<event logger=\"TestLogger\" timestamp=\"{0:s}\" level=\"INFO\" thread=\"TestThread\" domain=\"Tests\" identity=\"TestRunner\" username=\"TestRunner\"><message>Test message</message><properties><data name=\"{1}\" value=\"{2}\" /></properties></event>\r\n",
- XmlConvert.ToString(DateTime.Today),
+ XmlConvert.ToString(DateTime.Today, XmlDateTimeSerializationMode.Local),
key,
value);
}