二开案例.单据插件.写日志
【应用场景】使用插件保存上机操作日志和文件日志。
【案例演示】采购订单,在单据插件中保存上机操作日志和文件日志。
【实现步骤】
<1>编写单据插件,实现保存上机操作日志和文件日志的功能,代码如下。
using Kingdee.BOS;
using Kingdee.BOS.Core.Bill.PlugIn;
using Kingdee.BOS.Core.DynamicForm.PlugIn.Args;
using Kingdee.BOS.Core.Log;
using Kingdee.BOS.Log;
using Kingdee.BOS.ServiceHelper;
using Kingdee.BOS.Util;
using System;
using System.Collections.Generic;
using System.ComponentModel;
namespace Jac.XkDemo.BOS.Business.PlugIn
{
/// <summary>
/// 【单据插件】写日志
/// </summary>
[Description("【单据插件】写日志"), HotUpdate]
public class WriteLogBillPlugIn : AbstractBillPlugIn
{
/// <summary>
/// 主菜单点击事件
/// </summary>
/// <param name="e"></param>
public override void BarItemClick(BarItemClickEventArgs e)
{
base.BarItemClick(e);
if (e.BarItemKey.EqualsIgnoreCase("tbWriteDbLog"))
{
var logs = new List<LogObject>();
var log = new LogObject();
log.pkValue = this.View.Model.GetPKValue().ToString();
log.Description = "我是一条测试日志数据:)";
log.OperateName = "保存上机日志";
log.ObjectTypeId = this.View.Model.BillBusinessInfo.GetForm().Id;
log.SubSystemId = this.View.OpenParameter.SubSystemId;
log.Environment = OperatingEnvironment.BizOperate;
logs.Add(log);
LogServiceHelper.BatchWriteLog(this.Context, logs);
this.View.ShowMessage("上机操作日志已保存!");
return;
}
if (e.BarItemKey.EqualsIgnoreCase("tbWriteFileLog"))
{
Logger.Info("BOS", "我是一条测试日志数据:)");
Logger.Error("BOS", "我是一条测试日志数据:)", new KDException("?", "金蝶异常......"));
var logFilePath = AppDomain.CurrentDomain.BaseDirectory + "App_Data\\Log\\" + DateTime.Now.ToString("yyyy-MM-dd") + "\\Cloud.log";
this.View.ShowMessage(string.Format("文件日志已保存至应用服务器的以下路径:{0}", logFilePath));
return;
}
}
}
}
/*【Python插件】【单据插件】写日志
import clr
clr.AddReference("System")
clr.AddReference('Kingdee.BOS')
clr.AddReference('Kingdee.BOS.Core')
clr.AddReference('Kingdee.BOS.DataEntity')
clr.AddReference('Kingdee.BOS.ServiceHelper')
from System import *
from System.Collections.Generic import *
from Kingdee.BOS import *
from Kingdee.BOS.Core.Bill.PlugIn import *
from Kingdee.BOS.Core.Log import *
from Kingdee.BOS.Log import *
from Kingdee.BOS.ServiceHelper import *
from Kingdee.BOS.Util import *
def BarItemClick(e):
if (e.BarItemKey == "tbWriteDbLog"):
logs = List[LogObject]();
log = LogObject();
log.pkValue = this.View.Model.GetPKValue().ToString();
log.Description = "我是一条测试日志数据:)";
log.OperateName = "保存上机日志";
log.ObjectTypeId = this.View.Model.BillBusinessInfo.GetForm().Id;
log.SubSystemId = this.View.OpenParameter.SubSystemId;
log.Environment = OperatingEnvironment.BizOperate;
logs.Add(log);
LogServiceHelper.BatchWriteLog(this.Context, logs);
this.View.ShowMessage("上机操作日志已保存!");
return;
if (e.BarItemKey == "tbWriteFileLog"):
Logger.Info("BOS", "我是一条测试日志数据:)");
Logger.Error("BOS", "我是一条测试日志数据:)", KDException("?", "金蝶异常......"));
logFilePath = AppDomain.CurrentDomain.BaseDirectory + "App_Data\\Log\\" + DateTime.Now.ToString("yyyy-MM-dd") + "\\Cloud.log";
this.View.ShowMessage(String.Format("文件日志已保存至应用服务器的以下路径:{0}", logFilePath));
return;
*/
<2>拷贝插件组件到应用站点的WebSite\Bin目录下,重启IIS。
<3>BOSIDE扩展采购订单,菜单集合上添加两个菜单,注册表单插件,保存元数据,开发完毕。
现在可以登录业务站点,打开采购订单编辑界面,检验一下插件效果啦。
保存上机操作日志:
保存应用服务器文件日志:
【金蝶云星空BOS二次开发案例演示】https://vip.kingdee.com/article/94751030918525696
二开案例.单据插件.写日志
本文2024-09-23 04:21:21发表“云星空知识”栏目。
本文链接:https://wenku.my7c.com/article/kingdee-k3cloud-164772.html