问题
You are right, our customer have written a class inherit CustomTableItem class, which named as EventLogItem. We also have a CustomTable named as EventLog.
The problem should be, why we have so many logs with event code “CREATEOBJ” and “UPDATEOBJ”? I believe this kind of log was written by Kentico automatically.
Currently the log with event code “CREATEOBJ” and “UPDATEOBJ” are distracting when we try to do the troubleshooting.
Do you have the feature to turn off such kind of log? I would like to ignore such kind of log.
回答
These events are logged when you create or update the object.
This was requested by many customers so they can trace who changed what and when.
IF you do not want to log these, customize the event logging as described in the documentation:
https://docs.xperience.io/k12sp/custom-development/handling-global-events/customizing-event-logging
using CMS;
using CMS.DataEngine;
using CMS.EventLog;
using CMS.Base;
// Registers the custom module into the system
[assembly: RegisterModule(typeof(CustomInitializationModule))]
public class CustomInitializationModule : Module
{
// Module class constructor, the system registers the module under the name "CustomInit"
public CustomInitializationModule()
: base("CustomInit")
{
}
// Contains initialization code that is executed when the application starts
protected override void OnInit()
{
base.OnInit();
// Assigns a handler to the LogEvent.Before event
EventLogEvents.LogEvent.Before += LogEvent_Before;
}
private void LogEvent_Before(object sender, LogEventArgs e)
{
// Gets an object representing the event that is being logged
EventLogInfo eventLogRecord = e.Event;
// Cancels logging for events with the "CREATEOBJ" or "UPDATEOBJ" event codes.
// Disables event log records notifying about the creation or update of objects in the system,
// but still allows events related to object deletion.
string eventCode = eventLogRecord.EventCode;
if (eventCode.EqualsCSafe("CREATEOBJ") || eventCode.EqualsCSafe("UPDATEOBJ"))
{
e.Cancel();
}
// Adds a custom message to the Description field for events of the Information type
if (eventLogRecord.EventType.EqualsCSafe("I"))
{
eventLogRecord.EventDescription += " Custom message";
}
}
}
查看日志的时候,可以把这种数据过滤掉,does not contain