Command-line tool for parsing logs with mining using the Drain algorithm. Built on DrainDotNet, it clusters raw logs into structured templates for log analysis, anomaly detection, monitoring, and observability.
$ dotnet add package DrainDotNet.ToolDrainDotNet is a C# port and improvement of LogPai’s Drain log parser, with several improvements to make it faster, more reliable, and more user-friendly. It takes raw logs and automatically groups them into templates so you can easily see log patterns.
DrainCore → the pure clustering algorithm (tree, similarity, templates). No I/O.LogParser → a wrapper that handles regex-based parsing, preprocessing, saving to CSV, and reloading later.
This makes it easier to maintain and test the core logic separately.time: 15> ms, which used to confuse Drain and produce broken templates like time: <*>>.Parse() returns a List<ParsedLog> in code (with LineId, Content, EventId, EventTemplate, ParameterList, and extra fields), so you don’t have to re-parse CSVs if you want to use results directly.autoSave: false if you only want in-memory results.Put your log file in the data folder (see Program.cs for path).
Build and run the project.
Results will be written into the outputDir path specified:
*_structured.csv — each log line matched with a template (includes ParameterList).*_templates.csv — unique log templates with counts.Or use directly in code:
using DrainDotNet;
var logFormat = "<Date> <Time> <Pid> <Level> <Component> <Content>";
var parser = new LogParser(logFormat, indir: "./data/", outdir: "./result/");
// Parse logs and also save CSVs (default)
var parsedLogs = parser.Parse("HDFS.log");
// Parse logs but keep results in memory only
var parsedInMemory = parser.Parse("HDFS.log", autoSave: false);
// Reload results later (if auto saved) from saved CSVs
var reloaded = parser.ReloadResults("HDFS.log");
DrainDotNet is also available as a .NET global tool, so you can parse logs directly from the command line without writing code.
dotnet tool install -g DrainDotNet.Tool
draindotnet parse --log <logFile> --format "<LogFormat>" [--indir <inputDir>] [--out <outputDir>]
draindotnet parse --log HDFS_2k.log --format "<Date> <Time> <Pid> <Level> <Component>: <Content>" --indir ./SampleApp/data/loghub_2k/HDFS --out ./SampleApp/result
This will generate:
Apache 2.0 (same as the original Drain).