{"id":22835191,"url":"https://github.com/jchristn/openauditlog","last_synced_at":"2025-04-24T00:07:40.778Z","repository":{"id":65504649,"uuid":"333969442","full_name":"jchristn/OpenAuditLog","owner":"jchristn","description":"Simple C# event library providing event persistence and allowing you to write your own emitters","archived":false,"fork":false,"pushed_at":"2024-12-24T23:00:20.000Z","size":19217,"stargazers_count":4,"open_issues_count":0,"forks_count":1,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-04-24T00:07:31.053Z","etag":null,"topics":["audit","auditlog","auditlogging","event","events","syslog"],"latest_commit_sha":null,"homepage":"","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/jchristn.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE.md","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2021-01-28T22:10:09.000Z","updated_at":"2024-12-24T23:00:24.000Z","dependencies_parsed_at":"2023-01-26T13:31:06.691Z","dependency_job_id":null,"html_url":"https://github.com/jchristn/OpenAuditLog","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jchristn%2FOpenAuditLog","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jchristn%2FOpenAuditLog/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jchristn%2FOpenAuditLog/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jchristn%2FOpenAuditLog/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jchristn","download_url":"https://codeload.github.com/jchristn/OpenAuditLog/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250535099,"owners_count":21446508,"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":["audit","auditlog","auditlogging","event","events","syslog"],"created_at":"2024-12-12T22:08:38.924Z","updated_at":"2025-04-24T00:07:40.757Z","avatar_url":"https://github.com/jchristn.png","language":"C#","funding_links":[],"categories":[],"sub_categories":[],"readme":"![alt tag](https://github.com/jchristn/openauditlog/blob/main/assets/logo.ico)\n\n# OpenAuditLog\n\n[![NuGet Version](https://img.shields.io/nuget/v/OpenAuditLog.svg?style=flat)](https://www.nuget.org/packages/OpenAuditLog/) [![NuGet](https://img.shields.io/nuget/dt/OpenAuditLog.svg)](https://www.nuget.org/packages/OpenAuditLog) \n\nSimple C# event and audit log library with persistence allowing you to write your own emitters.\n\n## How it Works\n\n### Instantiate\n\nInstantiate the ```AuditLog``` object, specifying the name of the Sqlite database file to use.\n\n```csharp\nusing OpenAuditLog;\n\nAuditLog log = new AuditLog(\"auditlog.db\");\n```\n\n### Define Event Targets\n\nDefine and add your targets using ```AddTarget``` and the ```AuditLogTarget``` class.  Your target function should return a boolean with ```true``` indicating success, or, ```false``` indicating failure and that OpenAuditLog should try again.\n\n```csharp\nFunc\u003cAuditLogEntry, bool\u003e func1 = delegate (AuditLogEntry a)\n{\n  Console.WriteLine(\"Action 1: \" + a.ToJson(false));\n  return true; // report success\n};\n\nlog.AddTarget(\"MyTarget\", func1);\n```\n\n### Logger of Last Resort\n\nSet ```Logger``` if you wish to output messages to the console or elsewhere.  This also serves as a \"logger of last resort\" in case an event can't be sent to a target.  Additionally, you can create handlers for the ```EntrySendFailure``` and ```EntryEvicted``` events.\n\n```csharp\nlog.Logger = Console.WriteLine;\nlog.EntrySendFailure += MyEntrySendFailure;\nlog.EntryEvicted += MyEntryEvicted;\n\nstatic void MyEntrySendFailure(object sender, EntryEventArgs args)\n{\n  Console.WriteLine(\"Entry \" + args.Entry.GUID + \" couldn't be sent to target \" + args.Target.GUID);\n}\n\nstatic void MyEntryEvicted(object sender, EntryEventArgs args)\n{\n  Console.WriteLine(\"Entry \" + args.Entry.GUID + \" was evicted, failed too hard!\");\n}\n```\n\n### Let 'Er Rip\n\nAdd events using ```AddEvent``` and watch them fly.\n\nEvents added through ```AddEvent``` are persisted in Sqlite until emitted successfully.  If multiple targets are configured, one record per target will be created for each event.  You can control the number of attempts to send an event by modifying ```AuditLog.MaxAttempts``` or specify the optional parameter ```maxAttempts``` in ```AuditLog.AddEvent```.  \n\nEvents sent successfully are removed from Sqlite, and those that have failed the specified number of times will also be removed.  Refer to \"Logger of Last Resort\" above to determine how to intercept such situations.\n\n```csharp\n// build it yourself\nAuditLogEntry myEntry = new AuditLogEntry();\nmyEntry.Metadata = myClassInstance;\n// also set Identity, Source, Target, Resource, Type, etc, if you like\n```\n\n```csharp\n// or use the giga-constructor\nAuditLogEntry myEntry = new AuditLogEntry(metadata, identity, source, ...);\n```\n\nFire away!\n\n```csharp\nlog.AddEvent(myEntry);\n```\n\n## Simple Example\n\nRefer to the ```Test``` project for a full example.\n\n```csharp\nAuditLog auditLog = new AuditLog(\"auditlog.db\");\nauditLog.Logger = Console.WriteLine;\nauditLog.MaxAttempts = 3;\n\nFunc\u003cAuditLogEntry, bool\u003e myTarget = delegate (AuditLogEntry a)\n{\n    Console.WriteLine(\"My target: \" + a.ToJson(false));\n    return true; \n};\n\n// add the target\nauditLog.AddTarget(new AuditLogTarget(\"target1\", myTarget));\n\n// create the event\nAuditLogEntry entry = new AuditLogEntry();\nentry.Metadata = myClassInstance;\n// also set Identity, Source, Target, Resource, Type, etc\n\n// fire away!\nauditLog.AddEvent(entry);\n```\n\n## Version History\n\nRefer to ```CHANGELOG.md``` for version history.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjchristn%2Fopenauditlog","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjchristn%2Fopenauditlog","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjchristn%2Fopenauditlog/lists"}