File tree Expand file tree Collapse file tree 3 files changed +59
-0
lines changed
Expand file tree Collapse file tree 3 files changed +59
-0
lines changed Original file line number Diff line number Diff line change 1+ .vscode
2+ bin
3+ obj
Original file line number Diff line number Diff line change 1+ using Microsoft . Diagnostics . Tracing . Parsers ;
2+ using Microsoft . Diagnostics . Tracing . Session ;
3+
4+ namespace WinFileReadEvents
5+ {
6+ class Program
7+ {
8+ static void Main ( string [ ] args )
9+ {
10+ if ( TraceEventSession . IsElevated ( ) != true )
11+ {
12+ Console . WriteLine ( "x|To turn on ETW events you need to be Administrator, please run from an Admin process." ) ;
13+ return ;
14+ }
15+
16+ string ? filePath = ( args . Length < 1 ) ? null : args [ 0 ] ;
17+
18+ using var session = new TraceEventSession ( "FileRead" ) ;
19+
20+ Console . CancelKeyPress += ( sender , e ) => session . Stop ( ) ;
21+
22+ session . EnableKernelProvider (
23+ KernelTraceEventParser . Keywords . DiskFileIO |
24+ KernelTraceEventParser . Keywords . FileIOInit ) ;
25+
26+ session . Source . Kernel . FileIORead += data =>
27+ {
28+ if ( filePath == null || string . Compare ( data . FileName , filePath , StringComparison . OrdinalIgnoreCase ) == 0 )
29+ {
30+ string line = ">|" ;
31+ line += data . Offset + "|" ;
32+ line += data . IoSize + "|" ;
33+ line += data . FileName ;
34+ Console . WriteLine ( line ) ;
35+ }
36+ } ;
37+
38+ session . Source . Process ( ) ;
39+ }
40+ }
41+ }
Original file line number Diff line number Diff line change 1+ <Project Sdk =" Microsoft.NET.Sdk" >
2+
3+ <PropertyGroup >
4+ <OutputType >Exe</OutputType >
5+ <TargetFramework >net8.0</TargetFramework >
6+ <RootNamespace >WinFileReadEvents</RootNamespace >
7+ <ImplicitUsings >enable</ImplicitUsings >
8+ <Nullable >enable</Nullable >
9+ </PropertyGroup >
10+
11+ <ItemGroup >
12+ <PackageReference Include =" Microsoft.Diagnostics.Tracing.TraceEvent" Version =" 3.1.9" />
13+ </ItemGroup >
14+
15+ </Project >
You can’t perform that action at this time.
0 commit comments