|
| 1 | +// Copyright 2019 Serilog Contributors |
| 2 | +// |
| 3 | +// Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +// you may not use this file except in compliance with the License. |
| 5 | +// You may obtain a copy of the License at |
| 6 | +// |
| 7 | +// http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +// |
| 9 | +// Unless required by applicable law or agreed to in writing, software |
| 10 | +// distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +// See the License for the specific language governing permissions and |
| 13 | +// limitations under the License. |
| 14 | + |
| 15 | +using System; |
| 16 | +using System.IO; |
| 17 | +using System.Text; |
| 18 | + |
| 19 | +namespace Serilog.Sinks.File |
| 20 | +{ |
| 21 | + class FileLifeCycleHookChain : FileLifecycleHooks |
| 22 | + { |
| 23 | + private readonly FileLifecycleHooks _first; |
| 24 | + private readonly FileLifecycleHooks _second; |
| 25 | + |
| 26 | + public FileLifeCycleHookChain(FileLifecycleHooks first, FileLifecycleHooks second) |
| 27 | + { |
| 28 | + _first = first ?? throw new ArgumentNullException(nameof(first)); |
| 29 | + _second = second ?? throw new ArgumentNullException(nameof(second)); |
| 30 | + } |
| 31 | + |
| 32 | + public override Stream OnFileOpened(Stream underlyingStream, Encoding encoding) |
| 33 | + { |
| 34 | + var firstStreamResult = _first.OnFileOpened(underlyingStream, encoding); |
| 35 | + var secondStreamResult = _second.OnFileOpened(firstStreamResult, encoding); |
| 36 | + |
| 37 | + return secondStreamResult; |
| 38 | + } |
| 39 | + |
| 40 | + public override void OnFileDeleting(string path) |
| 41 | + { |
| 42 | + _first.OnFileDeleting(path); |
| 43 | + _second.OnFileDeleting(path); |
| 44 | + } |
| 45 | + } |
| 46 | +} |
0 commit comments