A slide-in panel that displays a filterable, searchable log of LogEntry items. Supports auto-scroll, level filtering, source filtering, copy, and clear operations.
<LogViewerPanel IsOpen="True"
Title="Activity Log"
PanelWidth="420" />| Property | Type | Default | Description |
|---|---|---|---|
IsOpen |
bool |
— | Whether the panel is visible |
Title |
string |
"Activity Log" |
Panel title |
AutoScroll |
bool |
true |
Whether the list auto-scrolls to new entries |
ShowDebugEntries |
bool |
false |
Whether Debug-level entries are shown |
SearchText |
string? |
— | Text used to filter entries by message content |
SelectedLevelFilter |
LogLevel? |
— | Level filter (null = show all levels) |
SelectedSourceFilter |
string? |
— | Source filter (null = show all sources) |
MaxEntries |
int |
5000 |
Maximum number of entries to retain |
PanelWidth |
double |
420 |
Width of the slide-in panel |
Entries |
ObservableCollection<LogEntry> |
— | Full collection of log entries |
FilteredEntries |
AvaloniaList<LogEntry> |
— | Filtered view of entries shown in the list |
LevelFilterOptions |
LogLevel?[] |
— | Available log level filter options |
SourceFilterOptions |
AvaloniaList<string?> |
— | Available source filter options |
| Event | Description |
|---|---|
Closed |
Raised when the panel is closed |
CopyAllRequested |
Raised when the user requests all entries to be copied |
CopyEntryRequested |
Raised when the user requests a single entry to be copied |
Control panel visibility:
<LogViewerPanel IsOpen="{Binding IsLogViewerOpen}" />logViewerPanel.Open();
logViewerPanel.Close();Append log entries to the panel:
// Simple message
logViewerPanel.Append(LogLevel.Information, "Operation completed");
// Full entry
logViewerPanel.Append(new LogEntry
{
Level = LogLevel.Error,
Message = "Failed to connect",
Source = "NetworkService",
Details = "Timeout after 30 seconds"
});Remove all entries:
logViewerPanel.Clear();Filter by log level:
logViewerPanel.SelectedLevelFilter = LogLevel.Error;Filter by source:
logViewerPanel.SelectedSourceFilter = "NetworkService";Filter by text search:
<LogViewerPanel SearchText="{Binding SearchText}" />Control whether debug entries are shown:
<LogViewerPanel ShowDebugEntries="True" />Control automatic scrolling to new entries:
<LogViewerPanel AutoScroll="True" />Set the maximum number of entries to retain (older entries are removed):
<LogViewerPanel MaxEntries="10000" />Adjust the width of the slide-in panel:
<LogViewerPanel PanelWidth="600" />Handle copy requests:
logViewerPanel.CopyAllRequested += (sender, e) =>
{
var text = string.Join("\n", logViewerPanel.FilteredEntries.Select(x => x.ToString()));
Clipboard.SetTextAsync(text);
};
logViewerPanel.CopyEntryRequested += (sender, entry) =>
{
Clipboard.SetTextAsync(entry.ToString());
};// In your ViewModel
public class MainViewModel
{
public LogViewerPanel LogViewer { get; } = new LogViewerPanel
{
Title = "Application Logs",
MaxEntries = 10000
};
private void LogOperation(string message, LogLevel level = LogLevel.Information)
{
LogViewer.Append(level, message, Source: "MainViewModel");
}
}The control applies pseudo-classes based on state:
:open- Applied when the panel is open:hasEntries- Applied when there are filtered entries:hasFilter- Applied when a filter is active
Use these for styling:
<Style Selector="LogViewerPanel:hasEntries">
<Setter Property="Background" Value="White" />
</Style>