Click or drag to resize

Manage audit(event logs) operations

You can perform various audit(Eventlog) operations via API.

Audit(EventLog) operations
Add following namespaces in your code
C#
using Novalys.VisualGuard.Security;
using Novalys.VisualGuard.Security.Common;
using Novalys.VisualGuard.Security.CommonProfileAttribute;
using Novalys.VisualGuard.Security.Database;
using Novalys.VisualGuard.Security.Logging;
using Novalys.VisualGuard.Security.Membership;
using Novalys.VisualGuard.Security.UserProfile;
using System;
using System.Collections.Generic;
using System.Collections.Specialized;
Define VisualGuard runtime
C#
VGSecurityRuntime runtime = VGSecurityManager.Runtime;
Get all eventlogs from storage

There are vaious methods available for getting eventlogs from storage. Few examples have been shown below.

C#
var currentApp = runtime.Application.GetCurrentApplication();

//get all eventlogs for application
var logs = runtime.EventLogs.GetAllEventLogByApplication(currentApp);

//get all eventlogs for application for given date range
int totalLogs = 0;

DateTime startDate = DateTime.Now.Date.Subtract(new TimeSpan(30, 0, 0, 0));
DateTime endDate = DateTime.Now.Date;            

//get all eventlogs for particular user for all applications for given date range
var logsbyUsername = runtime.EventLogs.GetAllEventLogByUsername("jsmith", startDate, endDate, 0, int.MaxValue, out totalLogs);

//Get all eventlogs for all applications
var allEventLogs= runtime.EventLogs.GetAllEventLog();

//Get eventlogs by category
var logsByCategory = runtime.EventLogs.GetAllEventLogByCategory(VGLogCategory.AccountLogon, startDate, endDate);
Add your own Custom EventId
C#
//few examples for adding new custom eventIds 
runtime.EventLogs.AddCustomVGEventId(101, "Viewing employee");
runtime.EventLogs.AddCustomVGEventId(102, "Viewing customer");
runtime.EventLogs.AddCustomVGEventId(103, "Change employee salary");
runtime.EventLogs.AddCustomVGEventId(104, "Viewing sales order");
runtime.EventLogs.AddCustomVGEventId(105, "SalesOrder modified");
runtime.EventLogs.AddCustomVGEventId(106, "SalesOrder deleted");
Write an event Log
C#
//define properties
StringDictionary dictionary = new StringDictionary();
dictionary.Add("Id", "143");
dictionary.Add("EmployeeName", "Peter");

//define logentry
var logentry_ViewEmployee = new VGLogEntry(101, "View Employee", "Consultation of Employee: [p:EmployeeName] [p:Id]", System.Diagnostics.TraceEventType.Information, dictionary);

//write log for application
runtime.WriteLog(logentry_ViewEmployee);


//define logentry
dictionary.Add("OldSal", "5000");
dictionary.Add("NewSal", "6000");
var logentry_ChangeEmployeeSalary = new VGLogEntry(103, "Change employee salary", "Changed employee salary from [p:OldSal] to [p:NewSal], for employee: [p:EmployeeName] ", System.Diagnostics.TraceEventType.Information, dictionary);


//write log for application
runtime.WriteLog(logentry_ChangeEmployeeSalary);

//you can also use following methods for writing log
Security.Logging.VGLogger.Write(logentry_ViewEmployee);
VGSecurityManager.WriteLog(logentry_ViewEmployee);
Get all custom eventIds
C#
 //Get all custom eventIds
var allCustomEventIds = runtime.EventLogs.GetAllCustomEventIds();
Delete custom eventId
C#
 //find particular EventId
var findEventId = allCustomEventIds.Find(x => x.EventId == 106);

//Delete customEventId
runtime.EventLogs.DeleteCustomVGEventId(findEventId);
Clear logs
C#
 //clears all logs for current application
runtime.EventLogs.ClearLog(currentApp);

//clears logs for current application older than 15 days
runtime.EventLogs.ClearLog(currentApp,DateTime.Now.Date.Subtract(new TimeSpan(15,0,0,0)));