{"id":21924912,"url":"https://github.com/judahgabriel/ravendb.structuredlog","last_synced_at":"2025-04-19T15:46:11.968Z","repository":{"id":138082013,"uuid":"104923606","full_name":"JudahGabriel/RavenDB.StructuredLog","owner":"JudahGabriel","description":"An ASP.NET Core logger that utilizes RavenDB to store structured logs.","archived":false,"fork":false,"pushed_at":"2024-03-26T07:07:22.000Z","size":1232,"stargazers_count":11,"open_issues_count":2,"forks_count":6,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-11T23:37:52.341Z","etag":null,"topics":["aspnetcore","logging","ravendb","structured-logging"],"latest_commit_sha":null,"homepage":"https://www.nuget.org/packages/RavenDB.StructuredLogger","language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/JudahGabriel.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2017-09-26T18:35:47.000Z","updated_at":"2024-11-19T15:19:35.000Z","dependencies_parsed_at":"2024-11-28T21:16:30.564Z","dependency_job_id":"c2c34e5a-729c-4afc-a5e4-8964873a4406","html_url":"https://github.com/JudahGabriel/RavenDB.StructuredLog","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JudahGabriel%2FRavenDB.StructuredLog","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JudahGabriel%2FRavenDB.StructuredLog/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JudahGabriel%2FRavenDB.StructuredLog/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JudahGabriel%2FRavenDB.StructuredLog/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/JudahGabriel","download_url":"https://codeload.github.com/JudahGabriel/RavenDB.StructuredLog/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":249730292,"owners_count":21317271,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["aspnetcore","logging","ravendb","structured-logging"],"created_at":"2024-11-28T21:16:25.197Z","updated_at":"2025-04-19T15:46:11.949Z","avatar_url":"https://github.com/JudahGabriel.png","language":"C#","funding_links":[],"categories":[],"sub_categories":[],"readme":"# RavenDB.StructuredLog\nAn ASP.NET Core logger that utilizes RavenDB to store structured logs.\n\n\u003ca href=\"https://andrewlock.net/creating-an-extension-method-for-attaching-key-value-pairs-to-scope-state-using-asp-net-core/\"\u003eStructured log\u003c/a\u003e that uses RavenDB as the log store.\n\nOld, ugly way of logging makes for thousands of opaque logs:\n- \"User foo@bar.com signed in at 5:13 Oct 7\"\n- \"User no@regerts.com signed in at 2:25 Nov 8\"\n- \"User bar@zanz.com signed in at 3:18 Nov 21\"\n- \"User me@me2.com signed in at 12:0 Dec 15\"\n- [and on and on for 1000+ entries - oiy!]\n\nBut with structured and grouped logging, you get a _fewer_ logs that group similar logs together and makes them searchable:\n```json\n{\n    \"MessageTemplate\": \"User {email} signed in at {date}\",\n    \"Level\": \"Information\",\n    \"OccurrenceCount\": 1032,\n    \"FirstOccurrence\": \"2017-09-27T17:29:46.6597966+00:00\",\n    \"LastOccurrence\": \"2017-09-27T17:39:50.5554997+00:00\",\n    \"Occurrences\": [\n        {\n            \"Message\": \"User foo@bar.com signed in at 5:13 Oct 7\",\n            \"Level\": \"Information\",\n            \"Created\": \"2017-09-27T17:39:48.4248681+00:00\",\n            \"Category\": \"Sample.Controllers.HomeController\",\n            \"EventId\": null,\n            \"TemplateValues\": {\n                \"{OriginalFormat}\": \"User {email} signed in at {date}\",\n                \"email\": \"foo@bar.com\",\n                \"date\": \"5:13 Oct 7\"\n            }\n        },\n        {\n            \"Message\": \"User no@regerts.com signed in at 2:25 Nov 8\",\n            \"Level\": \"Information\",\n            \"Created\": \"2017-09-27T17:39:48.4248681+00:00\",\n            \"Category\": \"Sample.Controllers.HomeController\",\n            \"EventId\": null,\n            \"TemplateValues\": {\n                \"{OriginalFormat}\": \"User {email} signed in at {date}\",\n                \"email\": \"no@regerts.com\",\n                \"date\": \"2:25 Nov 8\"\n            }\n        }\n    ]\n}\n```\n\nThe end result is humans can easily understand what errors are occurring in your software and how often. Moreover, unlike old school logging where logs are giant opaque strings, structured logs are searchable as their template values are extracted and stored outside the log message.\n\n## Instructions ##\n1. In Startup.cs:\n\n```csharp\npublic void ConfigureServices(IServiceCollection services)\n{\n\t// Create your Raven doc store\n\tvar docStore = new DocumentStore { ... };\n\n\t// Recommended: \n\t// Avoid logging objects that contain self referenced loops.\n\t// Must be done before .Initialize().\n\tdocStore.IgnoreSelfReferencingLoops();\n\t\n\tdocStore.Initialize();\n\n\t// Add RavenDB structured logging.\n\tservices.AddRavenStructuredLogger(docStore);  // docStore may be omitted if it's already in the DI container\n\n\t...\n}\n```\n\n2. Use logging as you normally would inside your controllers and services:\n```csharp\npublic class HomeController : Controller \n{\n\tprivate ILogger\u003cHomeController\u003e logger;\n\n\tpublic HomeController(ILogger\u003cHomeController\u003e logger)\n\t{\n\t\tthis.logger = logger;\n\t}\n\n\tpublic string Get()\n\t{\n\t\t// Simple logging\n\t\tlogger.LogInformation(\"Hi there!\");\n\n\t\t// Logging with templates\n\t\tlogger.LogInformation(\"The time on the server is {time}.\", DateTime.UtcNow);\n\n\t\t// Logging exceptions\n\t\tlogger.LogError(exception, \"Woops, an error occurred\");\n\t\t\n\t\t// Logging exceptions with templates\n\t\tlogger.LogError(exception, \"Woops, an error occurred executing {action} at {date}\", this.ControllerContext.ActionDescriptor.ActionName, DateTime.UtcNow);\n\n\t\t// Logging with scopes\n\t\tusing (logger.BeginScope(42))\n\t\t{\n\t\t\tlogger.LogInformation(\"This message will have forty-two stored with it\");\n\t\t}\n\n\t\t// Logging with multiple scopes and scope templates.\n\t\tusing (logger.BeginScope(42))\n\t\tusing (logger.BeginScope(\"The current user is {user}\", User.Identity.Name))\n\t\tusing (logger.BeginKeyValueScope(nameof(totalCount), totalCount))\n\t\t{\n\t\t\tlogger.LogInformation(\"This log will contain forty-two, the current signed in user name, and a key-value pair containing the name of the totalCount variable and its value.\");\n\t\t}\n\t\t\n\t\t...\n\t}\n}\n```\n\n3. You're done! \n\nNeed help? See the [sample app](https://github.com/JudahGabriel/RavenDB.StructuredLog/tree/master/Sample).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjudahgabriel%2Fravendb.structuredlog","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjudahgabriel%2Fravendb.structuredlog","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjudahgabriel%2Fravendb.structuredlog/lists"}