Kentico lots of log with event code “CREATEOBJ” and “UPDATEOBJ”

问题

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

 

作者:Chuck Lu    GitHub    
posted @   ChuckLu  阅读(25)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 全程不用写代码,我用AI程序员写了一个飞机大战
· DeepSeek 开源周回顾「GitHub 热点速览」
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 记一次.NET内存居高不下排查解决与启示
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了
历史上的今天:
2020-06-30 Reporting Services Single Sign On (SSO) Authentication - Part 1
2020-06-30 .NET - WindowStyle = hidden vs. CreateNoWindow = true?
2020-06-30 WebForms UnobtrusiveValidationMode requires a ScriptResourceMapping for 'jquery'. Please add a ScriptResourceMapping named jquery(case-sensitive)
2020-06-30 How to fix IIS website loading forever
2020-06-30 Cannot read configuration file due to insufficient permissions
2020-06-30 How To Implement Forms-Based Authentication in Your ASP.NET Application by Using C#.NET
2020-06-30 What is the difference between Version and 'Runtime Version' in .Net?
点击右上角即可分享
微信分享提示