~ifolder-dev/simias/trunk-packaging

« back to all changes in this revision

Viewing changes to src/core/Simias.log4net/src/Util/PatternStringConverters/.svn/text-base/EnvironmentPatternConverter.cs.svn-base

  • Committer: Jorge O. Castro
  • Date: 2007-12-03 06:56:46 UTC
  • Revision ID: jorge@ubuntu.com-20071203065646-mupcnjcwgm5mnhyt
* Remove a bunch of .svn directories we no longer need.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#region Copyright & License
2
 
//
3
 
// Copyright 2001-2005 The Apache Software Foundation
4
 
//
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
8
 
//
9
 
// http://www.apache.org/licenses/LICENSE-2.0
10
 
//
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.
16
 
//
17
 
#endregion
18
 
 
19
 
// .NET Compact Framework 1.0 has no support for Environment.GetEnvironmentVariable()
20
 
#if !NETCF
21
 
 
22
 
using System;
23
 
using System.Text;
24
 
using System.IO;
25
 
 
26
 
using log4net.Util;
27
 
using log4net.DateFormatter;
28
 
using log4net.Core;
29
 
 
30
 
namespace log4net.Util.PatternStringConverters
31
 
{
32
 
        /// <summary>
33
 
        /// Write an environment variable to the output
34
 
        /// </summary>
35
 
        /// <remarks>
36
 
        /// <para>
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.
40
 
        /// </para>
41
 
        /// </remarks>
42
 
        /// <author>Nicko Cadell</author>
43
 
        internal sealed class EnvironmentPatternConverter : PatternConverter
44
 
        {
45
 
                /// <summary>
46
 
                /// Write an environment variable to the output
47
 
                /// </summary>
48
 
                /// <param name="writer">the writer to write to</param>
49
 
                /// <param name="state">null, state is not set</param>
50
 
                /// <remarks>
51
 
                /// <para>
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"/>
55
 
                /// property.
56
 
                /// </para>
57
 
                /// </remarks>
58
 
                override protected void Convert(TextWriter writer, object state) 
59
 
                {
60
 
                        try 
61
 
                        {
62
 
                                if (this.Option != null && this.Option.Length > 0)
63
 
                                {
64
 
                                        // Lookup the environment variable
65
 
                                        string envValue = Environment.GetEnvironmentVariable(this.Option);
66
 
                                        if (envValue != null && envValue.Length > 0)
67
 
                                        {
68
 
                                                writer.Write(envValue);
69
 
                                        }
70
 
                                }
71
 
                        }
72
 
                        catch(System.Security.SecurityException secEx)
73
 
                        {
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);
78
 
                        }
79
 
                        catch (Exception ex) 
80
 
                        {
81
 
                                LogLog.Error("EnvironmentPatternConverter: Error occurred while converting environment variable.", ex);
82
 
                        }
83
 
                }
84
 
        }
85
 
}
86
 
 
87
 
#endif // !NETCF
 
 
b'\\ No newline at end of file'