百科.dev
全部条目在线工具AI 编程趋势榜开源项目技术资讯提交条目
登录
< 返回工具列表
N

NLogViewer

> 编程语言
开源

NlogViewer 是一个用于可视化 NLog 日志的 UI 控件库

99 stars0 点赞0 次浏览
访问官网GitHub

工具介绍

NlogViewer 是一个用于可视化 NLog 日志的 UI 控件库

Nuget

A NuGet-package is available here.

NLogViewer

NLogViewer is a ui control library to visualize NLog logs in your personal application. It is mainly based on Sentinel and its controls.

supported Framework: .NET8

Desktop application (Sentinel.NLogViewer.App)

GitHub Releases ship:

  • MSI installer (Sentinel.LogViewer--win-x64.msi): installs under Program Files with a license dialog (MIT), Start Menu shortcut, and optional features (desktop shortcut, .log association) selectable in Custom setup. Silent install: msiexec /i Sentinel.LogViewer--win-x64.msi /qn (optional features with higher install level stay off unless you raise INSTALLLEVEL or use transforms).
  • Portable ZIP (self-contained and framework-dependent): unpack and run Sentinel.NLogViewer.App.exe from any folder; a NLogViewer.portable marker file directs settings to appsettings.json beside the app (see README-Portable.txt in the ZIP). Installed (MSI) copies keep using per-user %LocalAppData%\Sentinel.NLogViewer.App\.

Build the installer locally (Windows): dotnet build installer/Sentinel.NLogViewer.Installer.wixproj -c Release — output installer/bin/Release/Sentinel.LogViewer.msi.

Versioning: MSI, portable ZIPs, and NuGet packages always use GitVersion fullSemVer (for example 3.2.0-124-wix-installer-implementation-and-portable-versions.88 on a feature branch, or 3.2.0 on a release tag). The Chocolatey Community package is the only exception; it uses a flattened prerelease such as 3.2.0-dev0000000004001. See chocolatey/README.md.

NLogViewer

Material Design Theme

This project also includes NLogViewer.MaterialDesign - a Material Design theme and style package for the NLogViewer control. The Material Design theme provides a modern, clean UI following Google's Material Design guidelines.

NLogViewer.MaterialDesign - View Project

Quick Start

1. Add Required References

Add the following NuGet package reference to your project:

xml

2. Configure Application Resources

In your App.xaml, add the NLogViewer theme and styles:

xml

    
        
            
                
                
            
        
    

3. Use the Control

Add the namespace and use the control in your XAML:

xaml

    
        
    

NLog Configuration

NLogViewer is subscribing to CacheTarget. By default, the NLogViewer is automatically creating a CacheTarget with loggingPattern "*" and LogLevel "Trace".

If you want to customize the loggingPattern and LogLevel, add the following to your Nlog.config.

xml

   
     
   

  
    
  

  
     
  

Customize

Control Buttons

The NLogViewer includes control buttons that allow you to manage log viewing behavior. The control buttons are organized in a GroupBox and can be controlled programmatically.

Control Buttons - All Visible

Control Buttons - Hidden

Control Properties:

  • AutoScroll - Automatically scroll to the newest log entry when new entries are added
  • ClearCommand - Command to clear all log entries from the viewer
  • Pause - Pause or resume logging to improve performance when not actively monitoring
  • ShowControlButtons - Controls the visibility of the entire control button group

Usage:

csharp
// Control auto-scroll behavior
nLogViewer.AutoScroll = true;  // Enable auto-scroll
nLogViewer.AutoScroll = false; // Disable auto-scroll

// Pause/resume logging
nLogViewer.Pause = true;  // Pause logging
nLogViewer.Pause = false; // Resume logging

// Hide the entire control button group
nLogViewer.ShowControlButtons = false;

XAML Binding:

xaml

Control Logic:

  • AutoScroll automatically scrolls to the bottom when new log entries are added
  • ClearCommand removes all log entries from the viewer
  • Pause stops listening for new log events to improve performance
  • The entire control group can be hidden using ShowControlButtons = false

Colors

Customize foreground or background of every logLevel

NLogViewer

Multi targeting

Use more than one instance of NLogViewer to match different rules.

Create 2 targets with their own rules.

xml

  
  

   
   

Set TargetName property to link them.

xml

Column Visibility

Control which columns are visible in the NLogViewer. You can dynamically show or hide individual columns using the provided Dependency Properties.

Column Visibility Properties

Available column visibility properties:

  • ShowIdColumn - Controls ID column visibility
  • ShowLevelColumn - Controls Level column visibility
  • ShowTimeStampColumn - Controls TimeStamp column visibility
  • ShowLoggerNameColumn - Controls LoggerName column visibility
  • Message column is always visible (no control available)

Usage:

csharp
// Hide specific columns
nLogViewer.ShowIdColumn = false;
nLogViewer.ShowLevelColumn = false;

// Show columns again
nLogViewer.ShowIdColumn = true;
nLogViewer.ShowLevelColumn = true;

XAML Binding:

xaml

Filter Buttons

The NLogViewer includes filter buttons that allow you to hide/show specific log levels. The filter buttons are organized in a GroupBox and can be controlled programmatically.

Filter Buttons - All Visible

Filter Buttons - Some Hidden

Filter Properties:

  • TraceFilter - Hide/show Trace level log entries
  • DebugFilter - Hide/show Debug level log entries
  • InfoFilter - Hide/show Info level log entries
  • WarnFilter - Hide/show Warn level log entries
  • ErrorFilter - Hide/show Error level log entries
  • FatalFilter - Hide/show Fatal level log entries
  • ShowFilterButtons - Controls the visibility of the entire filter button group

Usage:

csharp
// Hide specific log levels
nLogViewer.TraceFilter = true;  // Hide Trace entries
nLogViewer.DebugFilter = true;  // Hide Debug entries
nLogViewer.InfoFilter = true;   // Hide Info entries

// Show log levels again
nLogViewer.TraceFilter = false; // Show Trace entries
nLogViewer.DebugFilter = false; // Show Debug entries

// Hide the entire filter button group
nLogViewer.ShowFilterButtons = false;

XAML Binding:

xaml

Filter Logic:

  • When a filter property is set to true, entries of that log level are hidden
  • When a filter property is set to false, entries of that log level are shown
  • The filter buttons are ToggleButtons that automatically bind to these properties
  • The entire filter group can be hidden using ShowFilterButtons = false

Search Functionality

The NLogViewer includes search capabilities that filter log entries based on text patterns or regular expressions. Search terms are displayed as chips/tags and can be managed through the UI or programmatically.

Search Features:

  • Text Search - Case-insensitive substring matching
  • Regex Search - Full regular expression pattern matching
  • AND Logic - All search terms must match for an entry to be displayed
  • Search Highlighting - Matched text is highlighted in both message and logger name columns
  • Context Menu - Right-click search terms for edit/remove options

Search Properties:

  • CurrentSearchText - The text currently being typed in the search box
  • UseRegexSearch - Toggle between text search and regex search modes
  • ActiveSearchTerms - Collection of active search terms (read-only)
  • SearchHighlightBackground - Brush used to highlight matched text

Usage:

…

XAML Binding:

xaml

Search Logic:

  • Search terms are applied to both the message and logger name columns
  • AND logic: ALL active search terms must match for a log entry to be displayed
  • Text search is case-insensitive and performs substring matching
  • Regex search uses full .NET regular expression patterns
  • Invalid regex patterns show a warning dialog and are not added
  • Search highlighting works in real-time as you add/remove terms

Control Architecture

NLogViewer is built as a CustomControl with theming support:

Architecture:

  • CustomControl Base Class - Enables proper theming and styling
  • RelayCommand System - MVVM-compatible command system
  • Theme Support - Full support for custom themes including Material Design
  • Code Organization - Separation of concerns between UI and logic

Format output (ILogEventInfoResolver)

To format the output of a LogEventInfo, implement a new instance of ILogEventInfoResolver and bind it to the Resolver you want to customize:

csharp
/// 
/// Reformat the DateTime
/// 
public class FooTimeStampResolver : ILogEventInfoResolver
{
    public string Resolve(LogEventInfo logEventInfo)
    {
        return logEventInfo.TimeStamp.ToUniversalTime().ToString();
    }
}
csharp
NLogViewer1.TimeStampResolver = new FooTimeStampResolver();

Subscription Management (StartListen/StopListen)

The NLogViewer provides manual control over log event subscriptions through the StartListen() and StopListen() methods. These methods are particularly useful in docking systems or scenarios where the control's lifecycle needs to be managed manually.

Purpose: These methods were implemented to address Issue #90 - subscription disposal when undocking the viewer parent container. The issue occurred when NLogViewer controls were used in docking systems where the control would be moved between different parent windows, causing subscription leaks and improper disposal.

Root Cause: When undocking a control from a docking system, the Unloaded event is triggered, which automatically disposes the subscription. This means that after undocking, the control is no longer listening for log events. Therefore, StartListen() must always be called in the DockChanged event handler to restore the subscription after undocking.

Method Details:

StartListen()

  • Purpose: Starts listening for log events by subscribing to the cache target
  • When to use:
    • When undocking from a docking system
    • When the window loads again after being hidden
    • When resuming log monitoring after pausing
  • Behavior:
    • Subscribes to the CacheTarget's observable stream
    • Buffers log events for 100ms intervals for better performance
    • Automatically manages parent window references for proper disposal
    • Prevents duplicate subscriptions if already listening

StopListen()

  • Purpose: Stops listening for log events by disposing the subscription
  • When to use:
    • When docking in a docking system
    • When the window is being unloaded
    • When pausing log monitoring temporarily
  • Behavior:
    • Disposes the current subscription
    • Clears the listening state
    • Prevents memory leaks from orphaned subscriptions

Usage Example:

csharp
// Manual control in docking scenarios
private void OnDockChanged(object sender, DockChangedEventArgs e)
{
    // Control is being undocked - MUST call StartListen() because 
    // the Unloade

Issues· 0 开放

查看全部 Issues在 GitHub 打开

暂无开放 Issues,或尚未同步最近议题。

> 标签

C#

暂无评论,来聊聊你的看法吧

> 工具信息

发布日期2026年8月1日
最后更新2026年9月18日
分类编程语言
定价开源

> 相关工具

T
TypeScript
JavaScript 的超集,为前端与全栈提供静态类型
P
Python
通用编程语言,广泛用于 Web、数据与 AI
G
Go
Google 推出的简洁高效系统语言