JSON Log Summarizer
Build a command-line tool in C# that reads a log file in JSON Lines format (one JSON object per line) and summarizes it: how many entries there are for each severity level (Info, Warning, Error), which endpoints appear most often, and which endpoints produce the most errors. You'll read the file line by line, parse each line with System.Text.Json, skip broken lines without crashing, and print tidy tables. As a final step, you'll add a small ASP.NET Core web endpoint that serves the same summary as JSON. It's a great first C# project for learning records, LINQ, file handling and error handling.
- Estimate
- ~8.5h
- Steps
- 6
- Completed by
- 0
- Proposed by
- codeseed.app
ASP.NET Core · System.Text.Json
Project roadmap
- 01
Set up the project and sample log
~1hInstall the .NET SDK (8 or newer) and create a console project with dotnet new console. Add a sample file sample.jsonl with at least 50 lines, where each line looks like {"timestamp":"...","level":"Error","endpoint":"/api/orders","message":"..."}, and include a few broken lines on purpose. The program takes the file path as its argument. Done when: dotnet run -- sample.jsonl prints the number of lines in the file.
- 02
Parse each line
~1.5hDefine a record LogEntry(DateTime Timestamp, string Level, string Endpoint, string Message). Read the file line by line with File.ReadLines and parse each line with JsonSerializer.Deserialize<LogEntry>, using case-insensitive property names. Skip empty lines, and catch JsonException for broken ones, counting them instead of crashing. Done when: the program prints how many lines were parsed and how many were skipped.
- 03
Count by severity and endpoint
~1.5hUsing LINQ's GroupBy, count the entries per level (ignoring upper and lower case) and per endpoint. Also find the top 5 endpoints with the most Error entries. Put this logic in its own LogSummary class so it can be tested. Done when: the counts for sample.jsonl match what you count by hand.
- 04
Print tidy tables
~1hPrint three sections: entries per level, the 10 most frequent endpoints with their counts, and the top 5 error endpoints. Align the columns with string padding, for example $"{name,-30}{count,8}". End with a line showing parsed and skipped totals. Exit with code 1 if the file doesn't exist. Done when: the output is aligned and readable.
- 05
Serve the summary with ASP.NET Core
~2hAdd a --serve option. When it's used, start a minimal ASP.NET Core web app (WebApplication.CreateBuilder) with one endpoint, GET /summary, that returns the summary of the given file as JSON. Reuse the same LogSummary class. Done when: dotnet run -- sample.jsonl --serve starts a server, and opening /summary in the browser shows the JSON summary.
- 06
Add tests
~1.5hCreate an xUnit test project and test LogSummary with a few lines built in the test: level counts, endpoint counts, the top error endpoints, and that broken lines are counted as skipped. Done when: dotnet test passes.
Resources
Ready to build this?
Get a GitHub repo and start building. Your AI reviewer checks each step as you go.
Tech stack