Class LogPanelViewModel
Feeds the in-app log panel from Ring.
Inherited Members
Namespace: MOSAIC.ViewModels
Assembly: MOSAIC.dll
Syntax
public sealed class LogPanelViewModel : ObservableObject, INotifyPropertyChanged, INotifyPropertyChanging, IDisposable
Remarks
The panel pulls; the logger never pushes. Producers only ever write to the sink's channel, the sink's single writer thread fills the ring, and this view model copies whatever is new on the existing VisualizationTimer tick — so no data thread ever touches the bound collection, and no second timer is created for the panel.
The result is a tail view rather than a transcript: while the panel is closed, or while ticks are suspended for a resize drag, the ring simply overwrites and the panel resumes at the newest entries. The log file is the complete record.
Fields
MaxEntriesPerTick
Upper bound on entries appended per tick, so one burst costs a bounded amount of UI work instead of a visible stall.
Declaration
private const int MaxEntriesPerTick = 256
Field Value
| Type | Description |
|---|---|
| int |
MaxVisibleEntries
Hard cap on the bound collection, so a long session cannot grow the UI without limit.
Declaration
public const int MaxVisibleEntries = 1000
Field Value
| Type | Description |
|---|---|
| int |
Remarks
Half the ring, because the panel is the short tail and not the archive: the ring still holds DefaultCapacity entries and the file holds every one of them, while this cap is what bounds the rows the list keeps alive and the text the Copy button builds.
TransientFailureHeadline
Declaration
private const string TransientFailureHeadline = "Logging hit a problem and carried on. The log file is still being written. If it keeps happening, use Copy and include the note below in your report."
Field Value
| Type | Description |
|---|---|
| string |
TransientNoticeMs
How long the note about a recovered failure stays up, in milliseconds.
Declaration
private const long TransientNoticeMs = 30000
Field Value
| Type | Description |
|---|---|
| long |
Remarks
Long enough for a student who was not watching the panel to notice it, short enough that a logger which has been working ever since stops saying otherwise. It runs from the tick the failure was seen on rather than the one it happened on, so a panel opened afterwards still gets the full window.
WriterStoppedHeadline
Declaration
private const string WriterStoppedHeadline = "Log file stopped. The entries below are the only record left, so use Copy to keep them."
Field Value
| Type | Description |
|---|---|
| string |
_autoScroll
Declaration
[ObservableProperty]
private bool _autoScroll
Field Value
| Type | Description |
|---|---|
| bool |
_cursor
Declaration
private long _cursor
Field Value
| Type | Description |
|---|---|
| long |
_droppedCount
Declaration
[ObservableProperty]
[NotifyPropertyChangedFor("HasDropped")]
private long _droppedCount
Field Value
| Type | Description |
|---|---|
| long |
_isWriterStopped
Whether the file writer has stopped for good, which decides both what the banner claims and whether it is allowed to clear itself.
Declaration
[ObservableProperty]
[NotifyPropertyChangedFor("LogFailureHeadline")]
private bool _isWriterStopped
Field Value
| Type | Description |
|---|---|
| bool |
_logFailureDetail
What went wrong inside the logger itself, or null while it is healthy.
Declaration
[ObservableProperty]
[NotifyPropertyChangedFor("HasLogFailure")]
private string? _logFailureDetail
Field Value
| Type | Description |
|---|---|
| string |
Remarks
The one failure the log file cannot report, because the file is what failed. Two very different things route through the same counter, which is what IsWriterStopped separates: a writer that has given up, after which the panel really is the only record left, and a single stumble the logger carried on from — rotation failing to delete an old file because the student has it open in an editor is the ordinary one, since the sink shares the file for reading — after which the file is still being written.
_matching
Declaration
private readonly List<LogEntry> _matching
Field Value
| Type | Description |
|---|---|
| List<LogEntry> |
_noticeExpiryTicks
TickCount64 at which the transient note clears, or 0 when there is no note to clear — a stopped writer's banner never gets a deadline.
Declaration
private long _noticeExpiryTicks
Field Value
| Type | Description |
|---|---|
| long |
_reportedFailures
Declaration
private long _reportedFailures
Field Value
| Type | Description |
|---|---|
| long |
_running
Declaration
private bool _running
Field Value
| Type | Description |
|---|---|
| bool |
_scratch
Declaration
private readonly List<LogEntry> _scratch
Field Value
| Type | Description |
|---|---|
| List<LogEntry> |
_viewLevel
Which of the captured entries the panel displays. A view filter, never the capture level.
Declaration
[ObservableProperty]
private LogLevel _viewLevel
Field Value
| Type | Description |
|---|---|
| LogLevel |
Remarks
The two are deliberately separate. Narrowing this to Error to quieten the panel must not stop Info and Warn reaching the file, because that is exactly the context a bug report needs; widening it again reveals entries that were captured all along, since the filter runs over Ring rather than over the gate. What gets captured is MinimumLevel, fixed at startup, and nothing in this panel writes it.
clearCommand
The backing field for ClearCommand.
Declaration
private RelayCommand? clearCommand
Field Value
| Type | Description |
|---|---|
| RelayCommand |
openLogFolderCommand
The backing field for OpenLogFolderCommand.
Declaration
private RelayCommand? openLogFolderCommand
Field Value
| Type | Description |
|---|---|
| RelayCommand |
Properties
AutoScroll
Declaration
[ExcludeFromCodeCoverage]
public bool AutoScroll { get; set; }
Property Value
| Type | Description |
|---|---|
| bool |
CaptureLevelText
What the sink is recording, so the dropdown's tooltip can say plainly which of the two levels the dropdown is not touching.
Declaration
public string CaptureLevelText { get; }
Property Value
| Type | Description |
|---|---|
| string |
Remarks
Read on demand rather than observed: the capture level is startup state — the build default
plus the MOSAIC_LOG_LEVEL override — and no UI writes it.
ClearCommand
Gets an IRelayCommand instance wrapping Clear().
Declaration
[ExcludeFromCodeCoverage]
public IRelayCommand ClearCommand { get; }
Property Value
| Type | Description |
|---|---|
| IRelayCommand |
DroppedCount
Declaration
[ExcludeFromCodeCoverage]
public long DroppedCount { get; set; }
Property Value
| Type | Description |
|---|---|
| long |
Entries
The rows the panel shows, newest last. Only ever touched on the UI thread.
Declaration
public AvaloniaList<LogEntry> Entries { get; }
Property Value
| Type | Description |
|---|---|
| AvaloniaList<LogEntry> |
Remarks
An Avalonia.Collections.AvaloniaList<T> rather than an ObservableCollection for its range
operations: a tick appends its whole batch and trims the overflow in one notification each,
instead of one per row that the list would have to re-lay-out.
HasDropped
Whether the queue has ever overflowed, which is what the toolbar counter announces.
Declaration
public bool HasDropped { get; }
Property Value
| Type | Description |
|---|---|
| bool |
HasLogFailure
Whether the failure banner shows. False for the whole of a healthy session.
Declaration
public bool HasLogFailure { get; }
Property Value
| Type | Description |
|---|---|
| bool |
IsWriterStopped
Whether the file writer has stopped for good, which decides both what the banner claims and whether it is allowed to clear itself.
Declaration
[ExcludeFromCodeCoverage]
public bool IsWriterStopped { get; set; }
Property Value
| Type | Description |
|---|---|
| bool |
Levels
The levels offered by the toolbar dropdown. None is not one of them — a panel that shows nothing has no reason to be open.
Declaration
public IReadOnlyList<LogLevel> Levels { get; }
Property Value
| Type | Description |
|---|---|
| IReadOnlyList<LogLevel> |
LogFailureDetail
What went wrong inside the logger itself, or null while it is healthy.
Declaration
[ExcludeFromCodeCoverage]
public string? LogFailureDetail { get; set; }
Property Value
| Type | Description |
|---|---|
| string |
Remarks
The one failure the log file cannot report, because the file is what failed. Two very different things route through the same counter, which is what IsWriterStopped separates: a writer that has given up, after which the panel really is the only record left, and a single stumble the logger carried on from — rotation failing to delete an old file because the student has it open in an editor is the ordinary one, since the sink shares the file for reading — after which the file is still being written.
LogFailureHeadline
The banner's headline, in the student's terms: what happened and what to do.
Declaration
public string LogFailureHeadline { get; }
Property Value
| Type | Description |
|---|---|
| string |
Remarks
The strong claim is spent only on a stopped writer. A banner that announced the end of the log file on every internal failure would spend most sessions doing it over a logger that was working perfectly well, and a student who has learned to ignore that one ignores the real one with it.
LogFilePathText
Full path of the current log file, for the toolbar tooltip.
Declaration
public string LogFilePathText { get; }
Property Value
| Type | Description |
|---|---|
| string |
OpenLogFolderCommand
Gets an IRelayCommand instance wrapping OpenLogFolder().
Declaration
[ExcludeFromCodeCoverage]
public IRelayCommand OpenLogFolderCommand { get; }
Property Value
| Type | Description |
|---|---|
| IRelayCommand |
ViewLevel
Which of the captured entries the panel displays. A view filter, never the capture level.
Declaration
[ExcludeFromCodeCoverage]
public LogLevel ViewLevel { get; set; }
Property Value
| Type | Description |
|---|---|
| LogLevel |
Remarks
The two are deliberately separate. Narrowing this to Error to quieten the panel must not stop Info and Warn reaching the file, because that is exactly the context a bug report needs; widening it again reveals entries that were captured all along, since the filter runs over Ring rather than over the gate. What gets captured is MinimumLevel, fixed at startup, and nothing in this panel writes it.
Methods
Append(List<LogEntry>)
Appends a batch and drops whatever it pushed past MaxVisibleEntries, in one collection change each rather than one per row.
Declaration
private void Append(List<LogEntry> rows)
Parameters
| Type | Name | Description |
|---|---|---|
| List<LogEntry> | rows |
BuildClipboardText()
Every visible row as text, for the Copy button.
Declaration
public string BuildClipboardText()
Returns
| Type | Description |
|---|---|
| string |
Clear()
Declaration
[RelayCommand]
private void Clear()
Dispose()
Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
Declaration
public void Dispose()
OnAutoScrollChanged(bool)
Executes the logic for when AutoScroll just changed.
Declaration
private void OnAutoScrollChanged(bool value)
Parameters
| Type | Name | Description |
|---|---|---|
| bool | value | The new property value that was set. |
Remarks
This method is invoked right after the value of AutoScroll is changed.
OnAutoScrollChanged(bool, bool)
Executes the logic for when AutoScroll just changed.
Declaration
private void OnAutoScrollChanged(bool oldValue, bool newValue)
Parameters
| Type | Name | Description |
|---|---|---|
| bool | oldValue | The previous property value that was replaced. |
| bool | newValue | The new property value that was set. |
Remarks
This method is invoked right after the value of AutoScroll is changed.
OnAutoScrollChanging(bool)
Executes the logic for when AutoScroll is changing.
Declaration
private void OnAutoScrollChanging(bool value)
Parameters
| Type | Name | Description |
|---|---|---|
| bool | value | The new property value being set. |
Remarks
This method is invoked right before the value of AutoScroll is changed.
OnAutoScrollChanging(bool, bool)
Executes the logic for when AutoScroll is changing.
Declaration
private void OnAutoScrollChanging(bool oldValue, bool newValue)
Parameters
| Type | Name | Description |
|---|---|---|
| bool | oldValue | The previous property value that is being replaced. |
| bool | newValue | The new property value being set. |
Remarks
This method is invoked right before the value of AutoScroll is changed.
OnDroppedCountChanged(long)
Executes the logic for when DroppedCount just changed.
Declaration
private void OnDroppedCountChanged(long value)
Parameters
| Type | Name | Description |
|---|---|---|
| long | value | The new property value that was set. |
Remarks
This method is invoked right after the value of DroppedCount is changed.
OnDroppedCountChanged(long, long)
Executes the logic for when DroppedCount just changed.
Declaration
private void OnDroppedCountChanged(long oldValue, long newValue)
Parameters
| Type | Name | Description |
|---|---|---|
| long | oldValue | The previous property value that was replaced. |
| long | newValue | The new property value that was set. |
Remarks
This method is invoked right after the value of DroppedCount is changed.
OnDroppedCountChanging(long)
Executes the logic for when DroppedCount is changing.
Declaration
private void OnDroppedCountChanging(long value)
Parameters
| Type | Name | Description |
|---|---|---|
| long | value | The new property value being set. |
Remarks
This method is invoked right before the value of DroppedCount is changed.
OnDroppedCountChanging(long, long)
Executes the logic for when DroppedCount is changing.
Declaration
private void OnDroppedCountChanging(long oldValue, long newValue)
Parameters
| Type | Name | Description |
|---|---|---|
| long | oldValue | The previous property value that is being replaced. |
| long | newValue | The new property value being set. |
Remarks
This method is invoked right before the value of DroppedCount is changed.
OnIsWriterStoppedChanged(bool)
Executes the logic for when IsWriterStopped just changed.
Declaration
private void OnIsWriterStoppedChanged(bool value)
Parameters
| Type | Name | Description |
|---|---|---|
| bool | value | The new property value that was set. |
Remarks
This method is invoked right after the value of IsWriterStopped is changed.
OnIsWriterStoppedChanged(bool, bool)
Executes the logic for when IsWriterStopped just changed.
Declaration
private void OnIsWriterStoppedChanged(bool oldValue, bool newValue)
Parameters
| Type | Name | Description |
|---|---|---|
| bool | oldValue | The previous property value that was replaced. |
| bool | newValue | The new property value that was set. |
Remarks
This method is invoked right after the value of IsWriterStopped is changed.
OnIsWriterStoppedChanging(bool)
Executes the logic for when IsWriterStopped is changing.
Declaration
private void OnIsWriterStoppedChanging(bool value)
Parameters
| Type | Name | Description |
|---|---|---|
| bool | value | The new property value being set. |
Remarks
This method is invoked right before the value of IsWriterStopped is changed.
OnIsWriterStoppedChanging(bool, bool)
Executes the logic for when IsWriterStopped is changing.
Declaration
private void OnIsWriterStoppedChanging(bool oldValue, bool newValue)
Parameters
| Type | Name | Description |
|---|---|---|
| bool | oldValue | The previous property value that is being replaced. |
| bool | newValue | The new property value being set. |
Remarks
This method is invoked right before the value of IsWriterStopped is changed.
OnLogFailureDetailChanged(string?)
Executes the logic for when LogFailureDetail just changed.
Declaration
private void OnLogFailureDetailChanged(string? value)
Parameters
| Type | Name | Description |
|---|---|---|
| string | value | The new property value that was set. |
Remarks
This method is invoked right after the value of LogFailureDetail is changed.
OnLogFailureDetailChanged(string?, string?)
Executes the logic for when LogFailureDetail just changed.
Declaration
private void OnLogFailureDetailChanged(string? oldValue, string? newValue)
Parameters
| Type | Name | Description |
|---|---|---|
| string | oldValue | The previous property value that was replaced. |
| string | newValue | The new property value that was set. |
Remarks
This method is invoked right after the value of LogFailureDetail is changed.
OnLogFailureDetailChanging(string?)
Executes the logic for when LogFailureDetail is changing.
Declaration
private void OnLogFailureDetailChanging(string? value)
Parameters
| Type | Name | Description |
|---|---|---|
| string | value | The new property value being set. |
Remarks
This method is invoked right before the value of LogFailureDetail is changed.
OnLogFailureDetailChanging(string?, string?)
Executes the logic for when LogFailureDetail is changing.
Declaration
private void OnLogFailureDetailChanging(string? oldValue, string? newValue)
Parameters
| Type | Name | Description |
|---|---|---|
| string | oldValue | The previous property value that is being replaced. |
| string | newValue | The new property value being set. |
Remarks
This method is invoked right before the value of LogFailureDetail is changed.
OnTick()
Declaration
private void OnTick()
Remarks
Must never log from here: VisualizationTimer reports a subscriber's exception, so a panel that logged from inside its own tick would feed itself. Reading the logger's state, as RefreshHealth() does, is fine; writing to it is not.
OnViewLevelChanged(LogLevel)
Executes the logic for when ViewLevel just changed.
Declaration
private void OnViewLevelChanged(LogLevel value)
Parameters
| Type | Name | Description |
|---|---|---|
| LogLevel | value | The new property value that was set. |
Remarks
This method is invoked right after the value of ViewLevel is changed.
OnViewLevelChanged(LogLevel, LogLevel)
Executes the logic for when ViewLevel just changed.
Declaration
private void OnViewLevelChanged(LogLevel oldValue, LogLevel newValue)
Parameters
| Type | Name | Description |
|---|---|---|
| LogLevel | oldValue | The previous property value that was replaced. |
| LogLevel | newValue | The new property value that was set. |
Remarks
This method is invoked right after the value of ViewLevel is changed.
OnViewLevelChanging(LogLevel)
Executes the logic for when ViewLevel is changing.
Declaration
private void OnViewLevelChanging(LogLevel value)
Parameters
| Type | Name | Description |
|---|---|---|
| LogLevel | value | The new property value being set. |
Remarks
This method is invoked right before the value of ViewLevel is changed.
OnViewLevelChanging(LogLevel, LogLevel)
Executes the logic for when ViewLevel is changing.
Declaration
private void OnViewLevelChanging(LogLevel oldValue, LogLevel newValue)
Parameters
| Type | Name | Description |
|---|---|---|
| LogLevel | oldValue | The previous property value that is being replaced. |
| LogLevel | newValue | The new property value being set. |
Remarks
This method is invoked right before the value of ViewLevel is changed.
OpenLogFolder()
Declaration
[RelayCommand]
private void OpenLogFolder()
RebuildFromRing()
Declaration
private void RebuildFromRing()
RefreshHealth()
Pulls the logger's own health onto the bound properties, on the tick the panel already has.
Declaration
private void RefreshHealth()
Remarks
A healthy tick pays two interlocked reads — the dropped counter the toolbar shows and InternalFailureCount — the equality check the generated DroppedCount setter makes before it raises anything, and one field comparison for the notice deadline. Everything else, the message and WriterStopped included, is reached only on the tick a new failure lands on, and the counter never goes back down, so that is once per failure rather than once per tick.
SelectMatching(List<LogEntry>)
Narrows a batch to the rows the current view filter admits, into a reused buffer.
Declaration
private List<LogEntry> SelectMatching(List<LogEntry> batch)
Parameters
| Type | Name | Description |
|---|---|---|
| List<LogEntry> | batch |
Returns
| Type | Description |
|---|---|
| List<LogEntry> |
Start()
Subscribes to the shared 30 fps tick. Idempotent.
Declaration
public void Start()
Stop()
Unsubscribes. Idempotent. The timer stops itself once nobody is left.
Declaration
public void Stop()