protected override void OnModelCreating(DbModelBuilder modelBuilder) { var dbGeneral = ComDBFun.GetDBGeneralInfo(DBType.LogTrace); // if (dbGeneral.DataBaseType != DataBaseType.Oracle) { Database.SetInitializer(new Log_OperateTraceInitializer());//oracle 不建议使用EF,会导致字段名和数据库名必须加引号 } modelBuilder.Configurations.Add(new Log_OperateTraceMap()); // modelBuilder.Entity<Log_OperateTrace>().HasKey(s => s.Id); if (!string.IsNullOrEmpty(dbGeneral.SchemaName)) { modelBuilder.HasDefaultSchema(dbGeneral.SchemaName.ToUpper()); } base.OnModelCreating(modelBuilder); }
protected override void OnModelCreating(DbModelBuilder modelBuilder) { var dbGeneral = ComDBFun.GetDBGeneralInfo(DBType.LogMonitor); // if (dbGeneral.DataBaseType != DataBaseType.Oracle) { Database.SetInitializer(new Log_SystemMonitorInitializer()); } modelBuilder.Configurations.Add(new Log_SystemMonitorMap()); // modelBuilder.Entity<Log_SystemMonitor>().Property(a => a.DiskSpace).HasColumnType("xml"); //非空类型才能用作泛型参数 if (!string.IsNullOrEmpty(dbGeneral.SchemaName)) { modelBuilder.HasDefaultSchema(dbGeneral.SchemaName.ToUpper()); } base.OnModelCreating(modelBuilder); }
/// <summary> /// 注册日志组件到本系统,为日志组件准备基础信息:服务器IP、服务器主机名,系统名称等 /// </summary> /// <param name="sys">业务系统类型</param> /// <param name="application">应用程序的Application对象</param> /// <param name="bWriteStartLog">是否是启动日志</param> /// <param name="bLogMonitor">是否写定时监控日志</param> public static void RegisterLogInitMsg(SysCategory sys, object applicationObj = null, UserCfg userConfig = null, Dictionary <SysCategory, string> webAppName = null, bool bWriteStartLog = true, bool bLogMonitor = true) { webAppNames = webAppName ?? new Dictionary <SysCategory, string>(); new HttpCacheHelper().SetCache(AppConfig.GetCacheKey(CacheConst.userCfgInCode), userConfig, expireType: Expire.Month); userCfg = GetUserConfigItem(); userCfg = userCfg ?? new UserCfg(); dataCache = CacheFac.CacheFactory(); appender = AppenderFac.AppenderFactory(); logLevelCfg = AppConfig.GetFinalConfig("log2NetLevel", LogLevel.Debug, GetLog2NetLevel()); if (logLevelCfg == LogLevel.Off) { return; } // AutoMapperConfig.Configure();//注册AutoMapper #if NET bRegister = true; ApplicationVisitCount.ApplicationObj = applicationObj; #endif //var machineName = System.Web.HttpContext.Current.Server.MachineName;//服务器计算机名 var machineName = Environment.MachineName;//服务器计算机名 var server = ClientServerInfo.ClientInfo.GetIPAccordingHost(machineName); string serverIP = server.IP; dataCache.SetCache(AppConfig.GetCacheKey(CacheConst.serverIP), serverIP, expireType: Expire.Month); dataCache.SetCache(AppConfig.GetCacheKey(CacheConst.serverHost), machineName, expireType: Expire.Month); dataCache.SetCache(AppConfig.GetCacheKey(CacheConst.systemName), sys, expireType: Expire.Month); #region 使用EF自动创建数据库 try { var initTraceDBWhenOracle = AppConfig.GetFinalConfig("initTraceDBWhenOracle", false, LogApi.IsInitTraceDBWhenOracle()); // initTraceDBWhenOracle = "1"; var traceDBType = ComDBFun.GetDBGeneralInfo(DBType.LogTrace).DataBaseType; if (traceDBType != DataBaseType.Oracle || (traceDBType == DataBaseType.Oracle && initTraceDBWhenOracle)) { using (var context = new Log_OperateTraceContext()) //oracle 不建议使用EF,会导致字段名和数据库名必须加引号 { #if NET context.Database.Initialize(true); //EF6 #else context.Database.EnsureCreated(); //EFCore #endif } } var initMonitorDBWhenOracle = AppConfig.GetFinalConfig("initMonitorDBWhenOracle", false, LogApi.IsInitMonitorDBWhenOracle()); // initMonitorDBWhenOracle = "1"; var monitorDBType = ComDBFun.GetDBGeneralInfo(DBType.LogMonitor).DataBaseType; if (monitorDBType != DataBaseType.Oracle || (monitorDBType == DataBaseType.Oracle && initMonitorDBWhenOracle)) { using (var context = new Log_SystemMonitorContext()) { #if NET context.Database.Initialize(true); //EF6 #else context.Database.EnsureCreated(); //EFCore #endif } } } catch (Exception ex) { WriteExceptToFile(ex); } #endregion 使用EF自动创建数据库 if (bWriteStartLog) { WriteServerStartupLog();//系统启动的日志 } StartThreadToWriteFileToAppender(); //开启线程,将备份日志写到Appender中 //在线人数和访客人数的初始化 VisitOnline.VisitCountFactory.GetInstance().SetVisitNumWhenInit(); if (bLogMonitor) { WriteMonitorLogThread(); } }