123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116 |
- #region Apache License
- #endregion
- #if !NETCF
- using System;
- using System.Text;
- using System.IO;
- using log4net.Util;
- using log4net.DateFormatter;
- using log4net.Core;
- namespace log4net.Util.PatternStringConverters
- {
-
-
-
-
-
-
-
-
-
-
-
- internal sealed class EnvironmentPatternConverter : PatternConverter
- {
-
-
-
-
-
-
-
-
-
-
-
-
-
- override protected void Convert(TextWriter writer, object state)
- {
- try
- {
- if (this.Option != null && this.Option.Length > 0)
- {
-
- string envValue = Environment.GetEnvironmentVariable(this.Option);
- #if NET_2_0
-
- if (envValue == null)
- {
- envValue = Environment.GetEnvironmentVariable(this.Option, EnvironmentVariableTarget.User);
- }
-
- if (envValue == null)
- {
- envValue = Environment.GetEnvironmentVariable(this.Option, EnvironmentVariableTarget.Machine);
- }
- #endif
- if (envValue != null && envValue.Length > 0)
- {
- writer.Write(envValue);
- }
- }
- }
- catch(System.Security.SecurityException secEx)
- {
-
-
-
- LogLog.Debug(declaringType, "Security exception while trying to expand environment variables. Error Ignored. No Expansion.", secEx);
- }
- catch (Exception ex)
- {
- LogLog.Error(declaringType, "Error occurred while converting environment variable.", ex);
- }
- }
- #region Private Static Fields
-
-
-
-
-
-
-
- private readonly static Type declaringType = typeof(EnvironmentPatternConverter);
- #endregion Private Static Fields
- }
- }
- #endif // !NETCF
|