I have some kind of logs console, written in WPF. This console is based on RichTextBox. I moved this RichTextBox via constructor dependency injection to completely different class.
class LogManager
{
private readonly System.Windows.Controls.RichTextBox richTextBox;
private readonly FlowDocument flowDocument;
private readonly Paragraph commandParagraph;
public LogManager(System.Windows.Controls.RichTextBox richTextBox)
{
if (richTextBox == null)
{
throw new ArgumentNullException("richTextBox");
}
this.richTextBox = richTextBox;
flowDocument = new FlowDocument();
commandParagraph = new Paragraph();
richTextBox.Document = flowDocument;
// (...)
That's why I can changing the value of this box using:
commandParagraph.Inlines.Add(new Run("Some logs message"));
And it's working completely fine but too late. I'm getting my logs in some kind of packs and most of them income after program done his works. I'm guessing it's because of using only one thread to manage 'work' and 'logs'. I refer to LogManager by singleton
public sealed class UCSSBase : INotifyPropertyChanged
{
private static volatile UCSSBase instance;
private static object syncRoot = new Object();
private UCSSBase()
{
var progress = new Progress<string>(s => CurrentStatusElement = s);
GDM = new GeneticDataManager(progress);
dm = new DataManager(progress);
}
public static UCSSBase Instance
{
get
{
if (instance == null)
{
lock (syncRoot)
{
if (UCSSBase.logs == null)
throw new InvalidOperationException("Log console cannot be a null");
if (instance == null)
instance = new UCSSBase();
}
}
return instance;
}
}
private static LogManager logs;
internal static LogManager Logs
{
get
{
return UCSSBase.logs;
}
set
{
if(value == null)
{
throw new ArgumentNullException("value");
}
if (UCSSBase.logs != null)
{
throw new InvalidOperationException();
}
UCSSBase.logs = value;
}
}
//(...)
So, my question is, how can I easy change my program to allow my LogManager works independently from the rest of the system? (I refer in many places in the system to the console by this sigleton to add new logs)