Skip to content

Commit

Permalink
autoflush process logs
Browse files Browse the repository at this point in the history
  • Loading branch information
Jan0660 committed Jun 17, 2021
1 parent a0f5cb8 commit 067c835
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions JanD/JanDProcess.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,14 @@ public void Start()
return;
Console.WriteLine(
Ansi.ForegroundColor($"Starting: Name: {Name}; Command: {Command}", 0, 247, 247));
OutWriter ??= new StreamWriter(Path.Combine("./logs/") + Name + "-out.log", true);
ErrWriter ??= new StreamWriter(Path.Combine("./logs/") + Name + "-err.log", true);
OutWriter ??= new StreamWriter(Path.Combine("./logs/") + Name + "-out.log", true)
{
AutoFlush = true
};
ErrWriter ??= new StreamWriter(Path.Combine("./logs/") + Name + "-err.log", true)
{
AutoFlush = true
};
if (Watch && FileSystemWatcher == null)
{
FileSystemWatcher = new FileSystemWatcher(WorkingDirectory)
Expand Down Expand Up @@ -112,8 +118,8 @@ void Log(string whichStd, DataReceivedEventArgs eventArgs)
{
if (eventArgs.Data == null)
return;
var str = Ansi.ForegroundColor($"{Name} {whichStd}| ", (byte) (whichStd == "err" ? 255 : 0),
(byte) (whichStd == "out" ? 255 : 0), 0) + eventArgs.Data +
var str = Ansi.ForegroundColor($"{Name} {whichStd}| ", (byte)(whichStd == "err" ? 255 : 0),
(byte)(whichStd == "out" ? 255 : 0), 0) + eventArgs.Data +
'\n';
if (whichStd == "out")
OutWriter.Write(str);
Expand Down

0 comments on commit 067c835

Please sign in to comment.