-
Notifications
You must be signed in to change notification settings - Fork 25
Closed
Labels
enhancementNew feature or requestNew feature or request
Description
Export Functionality - Implementation Plan
Overview
Implement export functionality that allows users to export filtered log entries to a *.log file. The export will be accessible via a menu item that is only enabled when a tab is selected.
Implementation Steps
1. Create Export Models
- File:
app/Sentinel.NLogViewer.App/Models/ExportParameter.cs- Create
ExportParameterclass with:FilePath(string) - target file pathFormat(ExportFormat enum) - export format type
- Create
ExportFormatenum withLogas default value (extensible for future formats)
- Create
2. Add Export Command to NLogViewer
- File:
ui/Sentinel.NLogViewer.Wpf/NLogViewer.xaml.cs- Add
ExportCommanddependency property (ICommand) - Add method
GetFilteredLogEntries()that returnsIEnumerable<LogEventInfo>fromLogEvents.View(filtered collection) - Add method
ExportLogs(ExportParameter parameter)that:- Gets filtered log entries via
GetFilteredLogEntries() - Writes entries to file in NLog format (using TimeStampResolver, LoggerNameResolver, MessageResolver)
- Format:
[Timestamp] [Level] LoggerName: Message(with exception if present)
- Gets filtered log entries via
- Initialize
ExportCommandin constructor asRelayCommand<ExportParameter>(ExportLogs)
- Add
3. Add Export Command to MainViewModel
- File:
app/Sentinel.NLogViewer.App/ViewModels/MainViewModel.cs- Add
ExportLogsCommandproperty (ICommand) - Implement
ExportLogs()method that:- Checks if
SelectedTab != null - Opens
SaveFileDialogwith filter"Log Files (*.log)|*.log" - Finds
NLogViewerinstance from selected tab's visual tree (using helper method) - Creates
ExportParameterwith file path andExportFormat.Log - Calls
NLogViewer.ExportCommand.Execute(exportParameter)
- Checks if
- Add helper method
FindNLogViewerInTab()to locate NLogViewer instance - Initialize command in constructor:
ExportLogsCommand = new RelayCommand(ExportLogs, () => SelectedTab != null) - Update
CanExecutewhenSelectedTabchanges
- Add
4. Add Menu Item to MainWindow
- File:
app/Sentinel.NLogViewer.App/MainWindow.xaml- Add new
MenuItem"Logs" between "View" and "Help" menus - Structure:
Logs -> Export -> *.log format - Bind to
ExportLogsCommandfrom MainViewModel - Set
IsEnabledbinding to check ifSelectedTab != null
- Add new
5. Add Localization Resources (Optional)
- File:
app/Sentinel.NLogViewer.App/Resources/Resources.resx(and other language files)- Add keys:
Menu_Logs,Menu_Export,Menu_ExportLogFormat
- Add keys:
Technical Details
Export Format
The exported *.log file will use NLog standard format:
[dd-MM-yyyy hh:mm:ss.fff] [LEVEL] LoggerName: Message
Exception details (if present)
Finding NLogViewer Instance
Since NLogViewer is in a DataTemplate, we'll use visual tree traversal to find it:
- Start from the TabControl's selected tab content
- Traverse visual tree to find NLogViewer instance
- Use
VisualTreeHelperor recursive search
Filtered Log Entries
The export will use LogEvents.View.Cast<LogEventInfo>() which already applies all active filters (level filters and search terms).
Files to Modify
app/Sentinel.NLogViewer.App/Models/ExportParameter.cs(new)ui/Sentinel.NLogViewer.Wpf/NLogViewer.xaml.csapp/Sentinel.NLogViewer.App/ViewModels/MainViewModel.csapp/Sentinel.NLogViewer.App/MainWindow.xamlapp/Sentinel.NLogViewer.App/Resources/Resources.resx(optional)
Dependencies
Microsoft.Win32.SaveFileDialog(already used in MainViewModel)System.Windows.Media.VisualTreeHelperfor finding NLogViewer instance
Testing Checklist
- Test export functionality with filtered logs
- Test export with various log levels
- Test export with search filters applied
- Test menu item enable/disable based on tab selection
- Test SaveFileDialog functionality
- Verify exported file format matches NLog standard
Documentation
- Document export functionality in README
- Add screenshots of export menu and dialog
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
enhancementNew feature or requestNew feature or request