diff --git a/ln.logging/FileLogger.cs b/ln.logging/FileLogger.cs index dd92128..a403ed7 100644 --- a/ln.logging/FileLogger.cs +++ b/ln.logging/FileLogger.cs @@ -6,12 +6,18 @@ namespace ln.logging public class FileLogger : LoggingBackend, IDisposable { FileStream fileStream; + Stream foreignStream; TextWriter writer; public FileLogger(string filename) { openLogFile(filename); } + public FileLogger(Stream stream) + { + foreignStream = stream; + writer = new StreamWriter(foreignStream); + } private void openLogFile(string filename) { @@ -31,7 +37,7 @@ namespace ln.logging if (writer != null) { writer.Close(); - fileStream.Close(); + fileStream?.Close(); } } diff --git a/ln.logging/Logger.cs b/ln.logging/Logger.cs index 19664ab..06d1f2f 100644 --- a/ln.logging/Logger.cs +++ b/ln.logging/Logger.cs @@ -31,6 +31,10 @@ namespace ln.logging { Backends.Add(backend); } + public Logger(Stream logStream) + { + Backends.Add(new FileLogger(logStream)); + } public void Log(LogLevel level,string message, params object[] args) { diff --git a/ln.logging/ln.logging.csproj b/ln.logging/ln.logging.csproj index c41d934..a94c687 100644 --- a/ln.logging/ln.logging.csproj +++ b/ln.logging/ln.logging.csproj @@ -2,7 +2,7 @@ netcoreapp3.1 - 1.0.0 + 1.0.1 Harald Wolff-Thobaben l--n.de