ProtectCloseTextWriter.cs 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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 System;
  20. using System.IO;
  21. using System.Text;
  22. using log4net.Core;
  23. namespace log4net.Util
  24. {
  25. /// <summary>
  26. /// A <see cref="TextWriter"/> that ignores the <see cref="Close"/> message
  27. /// </summary>
  28. /// <remarks>
  29. /// <para>
  30. /// This writer is used in special cases where it is necessary
  31. /// to protect a writer from being closed by a client.
  32. /// </para>
  33. /// </remarks>
  34. /// <author>Nicko Cadell</author>
  35. public class ProtectCloseTextWriter : TextWriterAdapter
  36. {
  37. #region Public Instance Constructors
  38. /// <summary>
  39. /// Constructor
  40. /// </summary>
  41. /// <param name="writer">the writer to actually write to</param>
  42. /// <remarks>
  43. /// <para>
  44. /// Create a new ProtectCloseTextWriter using a writer
  45. /// </para>
  46. /// </remarks>
  47. public ProtectCloseTextWriter(TextWriter writer) : base(writer)
  48. {
  49. }
  50. #endregion Public Instance Constructors
  51. #region Public Properties
  52. /// <summary>
  53. /// Attach this instance to a different underlying <see cref="TextWriter"/>
  54. /// </summary>
  55. /// <param name="writer">the writer to attach to</param>
  56. /// <remarks>
  57. /// <para>
  58. /// Attach this instance to a different underlying <see cref="TextWriter"/>
  59. /// </para>
  60. /// </remarks>
  61. public void Attach(TextWriter writer)
  62. {
  63. this.Writer = writer;
  64. }
  65. #endregion
  66. #region Override Implementation of TextWriter
  67. /// <summary>
  68. /// Does not close the underlying output writer.
  69. /// </summary>
  70. /// <remarks>
  71. /// <para>
  72. /// Does not close the underlying output writer.
  73. /// This method does nothing.
  74. /// </para>
  75. /// </remarks>
  76. override public void Close()
  77. {
  78. // do nothing
  79. }
  80. #endregion Public Instance Methods
  81. }
  82. }