NewLinePatternConverter.cs 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. #region Apache License
  2. //
  3. // Licensed to the Apache Software Foundation (ASF) under one or more
  4. // contributor license agreements. See the NOTICE file distributed with
  5. // this work for additional information regarding copyright ownership.
  6. // The ASF licenses this file to you under the Apache License, Version 2.0
  7. // (the "License"); you may not use this file except in compliance with
  8. // the License. You may obtain a copy of the License at
  9. //
  10. // http://www.apache.org/licenses/LICENSE-2.0
  11. //
  12. // Unless required by applicable law or agreed to in writing, software
  13. // distributed under the License is distributed on an "AS IS" BASIS,
  14. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  15. // See the License for the specific language governing permissions and
  16. // limitations under the License.
  17. //
  18. #endregion
  19. using log4net.Core;
  20. namespace log4net.Util.PatternStringConverters
  21. {
  22. /// <summary>
  23. /// Writes a newline to the output
  24. /// </summary>
  25. /// <remarks>
  26. /// <para>
  27. /// Writes the system dependent line terminator to the output.
  28. /// This behavior can be overridden by setting the <see cref="PatternConverter.Option"/>:
  29. /// </para>
  30. /// <list type="definition">
  31. /// <listheader>
  32. /// <term>Option Value</term>
  33. /// <description>Output</description>
  34. /// </listheader>
  35. /// <item>
  36. /// <term>DOS</term>
  37. /// <description>DOS or Windows line terminator <c>"\r\n"</c></description>
  38. /// </item>
  39. /// <item>
  40. /// <term>UNIX</term>
  41. /// <description>UNIX line terminator <c>"\n"</c></description>
  42. /// </item>
  43. /// </list>
  44. /// </remarks>
  45. /// <author>Nicko Cadell</author>
  46. internal sealed class NewLinePatternConverter : LiteralPatternConverter, IOptionHandler
  47. {
  48. #region Implementation of IOptionHandler
  49. /// <summary>
  50. /// Initialize the converter
  51. /// </summary>
  52. /// <remarks>
  53. /// <para>
  54. /// This is part of the <see cref="IOptionHandler"/> delayed object
  55. /// activation scheme. The <see cref="ActivateOptions"/> method must
  56. /// be called on this object after the configuration properties have
  57. /// been set. Until <see cref="ActivateOptions"/> is called this
  58. /// object is in an undefined state and must not be used.
  59. /// </para>
  60. /// <para>
  61. /// If any of the configuration properties are modified then
  62. /// <see cref="ActivateOptions"/> must be called again.
  63. /// </para>
  64. /// </remarks>
  65. public void ActivateOptions()
  66. {
  67. if (SystemInfo.EqualsIgnoringCase(Option, "DOS"))
  68. {
  69. Option = "\r\n";
  70. }
  71. else if (SystemInfo.EqualsIgnoringCase(Option, "UNIX"))
  72. {
  73. Option = "\n";
  74. }
  75. else
  76. {
  77. Option = SystemInfo.NewLine;
  78. }
  79. }
  80. #endregion
  81. }
  82. }