【应用场景】使用插件保存上机操作日志和文件日志。
【案例演示】采购订单,在单据插件中保存上机操作日志和文件日志。
【实现步骤】<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; } } } }
var log = new LogObject(); log.Description = "点击扫码按钮:" + DateTime.Now.ToLongTimeString(); log.OperateName = "工序汇报扫码"; log.ObjectTypeId = this.View.Model.BillBusinessInfo.GetForm().Id; log.SubSystemId = this.View.OpenParameter.SubSystemId; log.Environment = OperatingEnvironment.BizOperate; LogServiceHelper.WriteLog(this.Context, log);