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 rg...@apache.org on 2008/01/03 02:05:49 UTC
svn commit: r608300 - in /logging/log4net/trunk:
src/Util/PatternStringConverters/EnvironmentPatternConverter.cs
tests/src/Util/EnvironmentPatternConverterTest.cs
tests/src/Util/SystemInfoTest.cs tests/src/log4net.Tests.vs2005.csproj
Author: rgrabowski
Date: Wed Jan 2 17:05:43 2008
New Revision: 608300
URL: http://svn.apache.org/viewvc?rev=608300&view=rev
Log:
Fix for LOG4NET-123. Process, User, and System level Environment variables (EnvironmentVariableTarget) are now recognized in EnvironmentPatternConverter under .NET 2.0. Patch submitted by Richard J Foster.
Added:
logging/log4net/trunk/tests/src/Util/EnvironmentPatternConverterTest.cs
Modified:
logging/log4net/trunk/src/Util/PatternStringConverters/EnvironmentPatternConverter.cs
logging/log4net/trunk/tests/src/Util/SystemInfoTest.cs
logging/log4net/trunk/tests/src/log4net.Tests.vs2005.csproj
Modified: logging/log4net/trunk/src/Util/PatternStringConverters/EnvironmentPatternConverter.cs
URL: http://svn.apache.org/viewvc/logging/log4net/trunk/src/Util/PatternStringConverters/EnvironmentPatternConverter.cs?rev=608300&r1=608299&r2=608300&view=diff
==============================================================================
--- logging/log4net/trunk/src/Util/PatternStringConverters/EnvironmentPatternConverter.cs (original)
+++ logging/log4net/trunk/src/Util/PatternStringConverters/EnvironmentPatternConverter.cs Wed Jan 2 17:05:43 2008
@@ -64,6 +64,21 @@
{
// Lookup the environment variable
string envValue = Environment.GetEnvironmentVariable(this.Option);
+
+#if NET_2_0
+ // If we didn't see it for the process, try a user level variable.
+ if (envValue == null)
+ {
+ envValue = Environment.GetEnvironmentVariable(this.Option, EnvironmentVariableTarget.User);
+ }
+
+ // If we still didn't find it, try a system level one.
+ if (envValue == null)
+ {
+ envValue = Environment.GetEnvironmentVariable(this.Option, EnvironmentVariableTarget.Machine);
+ }
+#endif
+
if (envValue != null && envValue.Length > 0)
{
writer.Write(envValue);
@@ -98,4 +113,4 @@
}
}
-#endif // !NETCF
\ No newline at end of file
+#endif // !NETCF
Added: logging/log4net/trunk/tests/src/Util/EnvironmentPatternConverterTest.cs
URL: http://svn.apache.org/viewvc/logging/log4net/trunk/tests/src/Util/EnvironmentPatternConverterTest.cs?rev=608300&view=auto
==============================================================================
--- logging/log4net/trunk/tests/src/Util/EnvironmentPatternConverterTest.cs (added)
+++ logging/log4net/trunk/tests/src/Util/EnvironmentPatternConverterTest.cs Wed Jan 2 17:05:43 2008
@@ -0,0 +1,91 @@
+// .NET Compact Framework 1.0 has no support for Environment.GetEnvironmentVariable()
+// .NET Framework version 1.0 / 1.1 do not have support for SetEnvironmentVariable which is used in these tests.
+#if !NETCF && NET_2_0
+
+using System;
+using System.IO;
+using System.Text;
+using NUnit.Framework;
+
+namespace log4net.Tests.Util
+{
+ [TestFixture]
+ public class EnvironmentPatternConverterTest
+ {
+ private const string ENVIRONMENT_VARIABLE_NAME = "LOG4NET_TEST_TEMP";
+ const string SYSTEM_LEVEL_VALUE = "SystemLevelEnvironmentValue";
+ const string USER_LEVEL_VALUE = "UserLevelEnvironmentValue";
+ const string PROCESS_LEVEL_VALUE = "ProcessLevelEnvironmentValue";
+
+ [Test]
+ public void SystemLevelEnvironmentVariable()
+ {
+ EnvironmentPatternConverter converter = new EnvironmentPatternConverter();
+ Environment.SetEnvironmentVariable(ENVIRONMENT_VARIABLE_NAME, SYSTEM_LEVEL_VALUE, EnvironmentVariableTarget.Machine);
+
+ converter.Option = ENVIRONMENT_VARIABLE_NAME;
+
+ StringWriter sw = new StringWriter();
+ converter.Convert(sw, null);
+
+ Assert.AreEqual(SYSTEM_LEVEL_VALUE, sw.ToString(), "System level environment variable not expended correctly.");
+
+ Environment.SetEnvironmentVariable(ENVIRONMENT_VARIABLE_NAME, null, EnvironmentVariableTarget.Machine);
+ }
+
+ [Test]
+ public void UserLevelEnvironmentVariable()
+ {
+ EnvironmentPatternConverter converter = new EnvironmentPatternConverter();
+ Environment.SetEnvironmentVariable(ENVIRONMENT_VARIABLE_NAME, USER_LEVEL_VALUE, EnvironmentVariableTarget.User);
+
+ converter.Option = ENVIRONMENT_VARIABLE_NAME;
+
+ StringWriter sw = new StringWriter();
+ converter.Convert(sw, null);
+
+ Assert.AreEqual(USER_LEVEL_VALUE, sw.ToString(), "User level environment variable not expended correctly.");
+
+ Environment.SetEnvironmentVariable(ENVIRONMENT_VARIABLE_NAME, null, EnvironmentVariableTarget.User);
+ }
+
+ [Test]
+ public void ProcessLevelEnvironmentVariable()
+ {
+ EnvironmentPatternConverter converter = new EnvironmentPatternConverter();
+ Environment.SetEnvironmentVariable(ENVIRONMENT_VARIABLE_NAME, PROCESS_LEVEL_VALUE);
+
+ converter.Option = ENVIRONMENT_VARIABLE_NAME;
+
+ StringWriter sw = new StringWriter();
+ converter.Convert(sw, null);
+
+ Assert.AreEqual(PROCESS_LEVEL_VALUE, sw.ToString(), "Process level environment variable not expended correctly.");
+
+ Environment.SetEnvironmentVariable(ENVIRONMENT_VARIABLE_NAME, null);
+ }
+
+ private class EnvironmentPatternConverter
+ {
+ private object target = null;
+
+ public EnvironmentPatternConverter()
+ {
+ target = Utils.CreateInstance("log4net.Util.PatternStringConverters.EnvironmentPatternConverter,log4net");
+ }
+
+ public string Option
+ {
+ get { return Utils.GetProperty(target, "Option") as string; }
+ set { Utils.SetProperty(target, "Option", value); }
+ }
+
+ public void Convert(TextWriter writer, object state)
+ {
+ Utils.InvokeMethod(target, "Convert", writer, state);
+ }
+ }
+ }
+}
+
+#endif
Modified: logging/log4net/trunk/tests/src/Util/SystemInfoTest.cs
URL: http://svn.apache.org/viewvc/logging/log4net/trunk/tests/src/Util/SystemInfoTest.cs?rev=608300&r1=608299&r2=608300&view=diff
==============================================================================
--- logging/log4net/trunk/tests/src/Util/SystemInfoTest.cs (original)
+++ logging/log4net/trunk/tests/src/Util/SystemInfoTest.cs Wed Jan 2 17:05:43 2008
@@ -28,9 +28,6 @@
/// <summary>
/// Used for internal unit testing the <see cref="SystemInfo"/> class.
/// </summary>
- /// <remarks>
- /// Used for internal unit testing the <see cref="SystemInfo"/> class.
- /// </remarks>
[TestFixture]
public class SystemInfoTest
{
@@ -101,4 +98,4 @@
t = SystemInfo.GetTypeFromString("LOG4NET.TESTS.UTIL.SYSTEMINFOTEST", true, false);
}
}
-}
\ No newline at end of file
+}
Modified: logging/log4net/trunk/tests/src/log4net.Tests.vs2005.csproj
URL: http://svn.apache.org/viewvc/logging/log4net/trunk/tests/src/log4net.Tests.vs2005.csproj?rev=608300&r1=608299&r2=608300&view=diff
==============================================================================
--- logging/log4net/trunk/tests/src/log4net.Tests.vs2005.csproj (original)
+++ logging/log4net/trunk/tests/src/log4net.Tests.vs2005.csproj Wed Jan 2 17:05:43 2008
@@ -33,7 +33,7 @@
<CheckForOverflowUnderflow>false</CheckForOverflowUnderflow>
<ConfigurationOverrideFile>
</ConfigurationOverrideFile>
- <DefineConstants>DEBUG;TRACE</DefineConstants>
+ <DefineConstants>TRACE;DEBUG;NET_2_0</DefineConstants>
<DocumentationFile>
</DocumentationFile>
<DebugSymbols>true</DebugSymbols>
@@ -149,6 +149,7 @@
<Compile Include="Util\CyclicBufferTest.cs">
<SubType>Code</SubType>
</Compile>
+ <Compile Include="Util\EnvironmentPatternConverterTest.cs" />
<Compile Include="Util\LogLogTest.cs" />
<Compile Include="Util\PatternStringTest.cs" />
<Compile Include="Util\PropertiesDictionaryTest.cs">