We have developed a plugin and now we want to create a new Audit Log on the user’s commands.
I followed your example “LogMessageToServer”, the example writes the Audit Log and I see it on Management Client.
In my plugin I created the same classes as in the example (“LogResourceHandler”); so I call the “LogResourceHandler.RegisterMyMessages()” method in “MyPluginDefinition.ini()” class.
On the client folder of my project, in the class that does something about the user command, I call the “LogResourceHandler.LogMyAction()” method to write the audit log, exactly in the same way of the example.
Nothing happens! I follow the debugging and there are no errors.
Where did I go wrong? Thank you
VideoOS.Platform.Log.LogClient is only supported in standalone. This is documented.
https://doc.developer.milestonesys.com/html/index.html?base=miphelp/class_video_o_s_1_1_platform_1_1_log_1_1_log_client.html&tree=tree_search.html?search=log
However I spent time on this and was able to find a workaround. You can use the LogClient in plugins if you follow these steps:
- In your plugin project add an reference to VideoOS.Platform.SDK.Log.
- In your plugin code add this initialization: VideoOS.Platform.SDK.Log.Environment.Initialize();
- Include dependent files by using the CopyLogFiles batch file in the MIP SDK Bin folder
TIP- I have the following post build event in Visual Studio
cd “[C:\Program](file:C:/Program) Files\Milestone\MIPSDK\Bin\”
call CopyLogFiles.bat “[C:\Program](file:C:/Program) Files\Milestone\MIPPlugins\$(TargetName)”
xcopy /y “$(TargetPath)” “[C:\Program](file:C:/Program) Files\Milestone\MIPPlugins\$(TargetName)”
xcopy /y “$(TargetDir)plugin.def” “[C:\Program](file:C:/Program) Files\Milestone\MIPPlugins\$(TargetName)\”
(The assumption that you use the same folder name as TargetName.)
Hi Andersen,
I also follow your instruction as above to insert our customise log message, but could you please update us how to insert the value for column ‘Category’ & ‘Source Type’ in audit log?
private static Dictionary<String,LogMessage> BuildDictionary(String culture)
{
Dictionary<String, LogMessage> messages = new Dictionary<string, LogMessage>();
//CustomMsg.Culture = new CultureInfo(culture);
messages.Add(\_id1, new LogMessage() { Id = \_id1, Category = "UserActions", Message = CustomMsg.sysLogout, Group = Group.Audit, Severity = [Severity.Info](https://Severity.Info), Status = Status.StatusQuo, RelatedObjectKind = Kind.Camera });
return messages;
}
public static void logoff()
{
Dictionary<String, String> parms = new Dictionary<string, string>();
Item item = new Item(EnvironmentManager.Instance.MasterSite, "System");
VideoOS.Platform.Log.LogClient.Instance.AuditEntry(\_myApplication, \_myComponent, \_id1, item, parms, PermissionState.Granted);
}
KennethT
Hi Bo and thanks for the suggestions.
I tried to follow your istructions and add all the necessary libraries but it not work in my plugin.
I saw the log files in “[C:\ProgramData\Milestone\XProtect](file:C:/ProgramData/Milestone/XProtect) Event Server\logs\MIPLogs”
and there is these errors:
2019-03-18 12:11:48.378 UTC+01:00 Error LogClientManager Unable to identify log server from item.ServerId - logentry NOT stored
2019-03-18 12:11:48.378 UTC+01:00 Error LogClient.NewEntry Exception:Server not logged on.
I think that the “log server” is not correctly identified, but how can i do it ?
This is what I did :
http://download.milestonesys.com/MIPSDK/Samples/AuditLogBackgroundPlugin.zip
This is taking code from the LogMessageToServer sample code and pasting it into the background plugin of a newly created plugin, where nothing else was changed.
For Category the LogMessageToServer sample shows Category = “UserActions” but this is not a valid choice and the Management Client shows “Unknown” when showing the log. Valid choices are:
“Unknown”
“Security”
“Management”
“Live”
“Playback”
“PTZ”
“IOAndEvents”
“Export”
“SmartWallControl”
“MapViewing”
“Bookmark”
“ManualRecording”
“Startup”
“Shutdown”
“License”
“Notification”
“SqlServerConnectivity”
“MediaStorage”
“EdgeStorage”
“Failover”
“RecorderCommunicationAndManagement”
“HardwareAndDevices”
“ExternalComponents”
“Plugins”
“Webserver”
(I found this list in my installed XProtect at [C:\Program](file:C:/Program) Files\Milestone\XProtect Management Server\LogServiceMsgs)
You cannot set “Source Type” it is hard-coded to “Device”.
PS. @Kenneth Tang Please make a new question in the forum instead of writing onto an existing question, doing so will greatly increase the usability of the Developer Forum.