Hangfire.Console icon indicating copy to clipboard operation
Hangfire.Console copied to clipboard

Clear lines or empty all old lines, WriteLine

Open aria321 opened this issue 6 years ago • 2 comments

Thanks for your great extension it is so useful for me, this is not issue but I have a request or maybe question, as you told us Console.WriteLine() can write a new line of string in Job details, as I see the code there are several overridden WriteLine there, but suppose I am sending 2000 files in a Job with a ProgressBar, everything works well with Progress Bar but each time I have to write some infos about current file which is working on, but the WriteLine() method at the end there are 2000 lines of string in details I want to write one line not append new line.

Is there a way to Clear all lines and write a new one ?

Or is there a workaround to achieve this target ?

Thanks in advance.

aria321 avatar Dec 17 '18 08:12 aria321

Hi @AHassanabadi. Unfortunately, no. And for two reasons:

  1. Hangfire storage API for Sets doesn't support range deletes, so we cannot just delete a last entry. We can only clear the entire set, but then everything written before would be lost beyond recovery.
  2. Client-side JS uses the previous line count for incremental live updates. So even if it was possible to remove and old line and add a new one instead, the total line count would still remain the same, so the console in Dashboard won't be updated automatically.

pieceofsummer avatar Jan 29 '19 00:01 pieceofsummer

Hi @pieceofsummer, Firstly I should thank you for providing useful library, so there is no way to do this, I saw all WriteLine() overloads their codes unavailable on my solution, anyway I thought the string line are stored somewhere and JS is fetching them in two-way connection for this reason I thought it is possible to prepare a method named Clear() or context.ResetLines() can delete all context lines like:

context.SetTextColor(ConsoleTextColor.White); 
//context.Clear()
context.WriteLine(prompt);
context.ResetTextColor(); 

based on your mentioned reasons it can't be done,.

if you think it is enough to close this issue I will close.

Thanks @pieceofsummer

aria321 avatar Jan 29 '19 14:01 aria321