1
#region Copyright & License
3
// Copyright 2001-2005 The Apache Software Foundation
5
// Licensed under the Apache License, Version 2.0 (the "License");
6
// you may not use this file except in compliance with the License.
7
// You may obtain a copy of the License at
9
// http://www.apache.org/licenses/LICENSE-2.0
11
// Unless required by applicable law or agreed to in writing, software
12
// distributed under the License is distributed on an "AS IS" BASIS,
13
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
// See the License for the specific language governing permissions and
15
// limitations under the License.
19
// .NET Compact Framework 1.0 has no support for Environment.GetEnvironmentVariable()
27
using log4net.DateFormatter;
30
namespace log4net.Util.PatternStringConverters
33
/// Write an environment variable to the output
37
/// Write an environment variable to the output writer.
38
/// The value of the <see cref="log4net.Util.PatternConverter.Option"/> determines
39
/// the name of the variable to output.
42
/// <author>Nicko Cadell</author>
43
internal sealed class EnvironmentPatternConverter : PatternConverter
46
/// Write an environment variable to the output
48
/// <param name="writer">the writer to write to</param>
49
/// <param name="state">null, state is not set</param>
52
/// Writes the environment variable to the output <paramref name="writer"/>.
53
/// The name of the environment variable to output must be set
54
/// using the <see cref="log4net.Util.PatternConverter.Option"/>
58
override protected void Convert(TextWriter writer, object state)
62
if (this.Option != null && this.Option.Length > 0)
64
// Lookup the environment variable
65
string envValue = Environment.GetEnvironmentVariable(this.Option);
66
if (envValue != null && envValue.Length > 0)
68
writer.Write(envValue);
72
catch(System.Security.SecurityException secEx)
74
// This security exception will occur if the caller does not have
75
// unrestricted environment permission. If this occurs the expansion
76
// will be skipped with the following warning message.
77
LogLog.Debug("EnvironmentPatternConverter: Security exception while trying to expand environment variables. Error Ignored. No Expansion.", secEx);
81
LogLog.Error("EnvironmentPatternConverter: Error occurred while converting environment variable.", ex);
b'\\ No newline at end of file'