Events Class |
Namespace: AskiaPortalCmn
The Events type exposes the following members.
Name | Description | |
---|---|---|
Find |
Finds all occurrences in the database using the passed filters
| |
FindAllLogTags |
Find all possible logs tags
|
The term `System` refer to the regular logs that could contains sensitive system information.
Example: "Execute SQL query on server with id 3 to create a new survey"
The term `Activity` refer to the user friendly logs and should not contains sensitive system information.
Example: "Creating a new survey"
Add new events
using System; using AskiaPortalCmn.Events; private static Guid TestLoggerGuid = Guid.Parse("590A6BE2-AA7E-49EF-8FBE-8C261C45E4F3"); private static Version TestLoggerVersion = new Version("1.0.0.0"); private static int Main(string[] args) { Events.System.Log(null, "Starting the `testLogger` application", new List<string>{"start"}); AskiaPortalCmnApi.OnSetup += AskiaPortalCmnApi_OnSetup; AskiaPortalCmnApi.InitializeModule(TestLoggerGuid, TestLoggerVersion); var context = ContextFactory.CreateForSuperAdmin(); var result = Context.Validate(); if (!result.Success) { Events.System.Error(null, result.Exception); return -1; } Events.System.Debug(context, "Doing some action..."); // Do the action var code = DoAction(); if (code != 0) { Events.Activity.Warn(context, $"Action done with the error code {code}"); } else { Events.Activity.Info(context, "Action done successfully."); } return code; } private void AskiaPortalCmnApi_OnSetup(IModuleSetup moduleSetup, IModule module) { Events.System.Info(null, $"Register the version `{moduleSetup.Version}` of the module `TestLogger`"); moduleSetup.Name = "TestLogger"; moduleSetup.Description = "Test logger"; moduleSetup.Authors = "Askia SAS"; moduleSetup.RootUrl = "/TestLogger"; try { moduleSetup.Save(); } catch (Exception ex) { Events.System.Fatal(null, ex); } }
Read all events of the current user during the last minute -1
private static void PrintCurrentUserLastEvents(IContext context) { Events.System.Info(context, $"Reading the last user logs"); var filter = new EventsFilter { From = DateTime.UtcNow.AddMinutes(-2), To = DateTime.UtcNow.AddMinutes(-1), UserId = new List<int> { context.User.Id } }; var logs = Events.FindAll(context, filter); foreach(var log in logs) { Console.WriteLine($"{log.Id} {log.CreatedAt} {log.Level} {log.Type} {log.Message}"); } }