private static ILog LogServiceRequested(ServiceProvider services) { ILog log = new LogImpl(); services.Add<ILog>(log); return log; }
//读卡 public IDCard ReadCard(IDCard IC) { try { iConnectionState = IC.InitComm(); if (iConnectionState == 1) { int iResult = 0; while (iResult != 2) { iResult = IC.ReadCardContent(); Thread.Sleep(100); } } else { IC = null; } } catch (Exception ex) { IC = null; LogImpl.Error(string.Format("{0}{2}{1}", ex.StackTrace, ex.Message, System.Environment.NewLine)); } return(IC); }
public TcpServer(String ipAddress = DefaultServerIpAddress, UInt16 port = DefaultServerPort, ILog logger = null, Boolean debug = true, TcpServerConfig config = null) { _config = config ?? new TcpServerConfig(); AssignIpAddressAndPort(ipAddress, port); _clientProcessingTasks = new Task[_config.ParallelTask]; _clientConnectingTask = new Task(ClientConnectProcessing, new CancellationToken(_interruptRequested)); if (logger != null) { _logger = logger; } else { Hierarchy hierarchy = (Hierarchy)LogManager.GetRepository(); Logger loggerImpl = hierarchy.LoggerFactory.CreateLogger(hierarchy, "Logger4Tests"); loggerImpl.Hierarchy = hierarchy; loggerImpl.AddAppender(new RollingFileAppender()); loggerImpl.AddAppender(new ColoredConsoleAppender()); loggerImpl.Repository.Configured = true; hierarchy.Threshold = debug ? Level.Debug : Level.Info; loggerImpl.Level = Level.All; _logger = new LogImpl(loggerImpl); } if (debug) { _logger.Debug("Server was inited in DEBUG mode"); } }
public ILogger CreateLogger(string categoryName) { var logger = _loggerRepository.GetLogger(categoryName); var impl = new LogImpl(logger); return(new Log4NetLogger(impl)); }
public static void configureLogs() { var hierarchy = (Hierarchy)LogManager.GetRepository(); hierarchy.Threshold = Level.Debug; // Configure LoggerA string logNameA = @"EventLog"; string fileNameA = @"Event_Log.txt"; var loggerA = hierarchy.LoggerFactory.CreateLogger(LogManager.GetRepository(), "EventLog"); loggerA.Hierarchy = hierarchy; loggerA.AddAppender(CreateFileAppender(logNameA, fileNameA)); loggerA.Repository.Configured = true; loggerA.Level = Level.Debug; eventLog = new LogImpl(loggerA); // Configure LoggerB string logNameB = @"ErrorLog"; string fileNameB = @"Error_Log.txt"; var loggerB = hierarchy.LoggerFactory.CreateLogger(LogManager.GetRepository(), "ErrorLog"); loggerB.Hierarchy = hierarchy; loggerB.AddAppender(CreateFileAppender(logNameB, fileNameB)); loggerB.Repository.Configured = true; loggerB.Level = Level.Debug; errorLog = new LogImpl(loggerB); }
private void button16_Click(object sender, EventArgs e) { LogImpl.Debug("Debug"); LogImpl.Error("错误信息"); LogImpl.Fatal("Fatal"); LogImpl.Info("Info"); LogImpl.Warn("警告Warn"); }
public static void Init() { Main = new LogImpl("Main"); Battle = new LogImpl("Battle"); UI = new LogImpl("UI"); Damage = new LogImpl("Damage"); Damage.Enable = false; }
public bool Init() { if (!isInit) { log = LogFactory.GetInstance(LSystem.GetSystemAppName()); isInit = true; } return(isInit); }
private void CanExam(IAsyncResult result) { LogImpl.Debug("读卡成功"); var ar = (AsyncResult)result; var md = (Func <IDCard, IDCard>)ar.AsyncDelegate; var IC = md.EndInvoke(result); if (IC == null) { } }
public virtual LogImpl CreateLog(String actorId, EventType eventType) { LogImpl log = new LogImpl(actorId, DateTime.Now, eventType, this); if (_logs == null) { _logs = new ListSet(); } _logs.Add(log); return(log); }
public ILogger CreateLogger(string categoryName) { Log4NetLogger CreateLog4NetLogger(string category) { var logger = _loggerRepository.GetLogger(category); var impl = new LogImpl(logger); return(new Log4NetLogger(impl)); } return(_loggerCache.GetOrAdd(categoryName, CreateLog4NetLogger)); }
private static LogImpl rootLogger = null; // Lazy init public static void Init() { if (rootLogger == null) { rootLogger = new LogImpl("", LogLevel.Debug); } if (loggers == null) { loggers = new Dictionary <string, ILog>(); } }
/// <summary> /// 使用日志的名字获取log4net对象,如果没有配置文件,则使用默认的配置创建对象并返回 /// </summary> /// <param name="loggerName">如果使用的是配置文件,则是<logger name="loggerName">标签中的 /// name属性的值</param> /// <param name="category"> /// 文件的上层文件夹,即类别,当使用默认配置时: /// <para>如果有值,则生成的日志路径为Log\{category}\{短时间}.log;</para> /// <para>如果没值,则生成的路径为Log\{短时间}.log</para> /// </param> /// <param name="additivity">该值指示子记录器是否继承其父级的appender。</param> /// <returns></returns> internal static ILog GetLogger(string loggerName, string category = null, bool additivity = false) { if (loggerContainer.ContainsKey(loggerName)) { return(loggerContainer[loggerName]); } if (UseConfig) { string path = ConfigPath; //首先判断根目录下是否有log4net.config文件 if (string.IsNullOrEmpty(path)) { path = AppDomain.CurrentDomain.SetupInformation.ApplicationBase + (@"\log4net.config"); } if (File.Exists(path)) { XmlConfigurator.ConfigureAndWatch(new FileInfo(path)); } } ILog log = LogManager.Exists(loggerName); if (UseConfig && log == null) { throw new Exception("获取对象失败,请指定正确的日志名或者配置文件!"); } if (log == null) { IAppender newAppender = GetNewFileApender(null, loggerName, category); Hierarchy repository = (Hierarchy)LogManager.GetRepository(); Logger logger = repository.LoggerFactory.CreateLogger(repository, loggerName); logger.Hierarchy = repository; logger.Parent = repository.Root; logger.Level = Level.Info; logger.Additivity = additivity; logger.AddAppender(newAppender); logger.Repository.Configured = true; log = new LogImpl(logger); } loggerContainer.TryAdd(loggerName, log); return(log); //return loggerContainer.GetOrAdd(loggerName, delegate (string name) //{ // ILog log= LogManager.Exists(loggerName); // return log; //}); }
public static ILog GetLogger(string loggerName, string logFile, string conversionPattern, int maxSizeRollBackups, string datePattern, string maximumFileSize) { Hierarchy hierarchy = (Hierarchy)LogManager.GetRepository(); hierarchy.Threshold = Level.All; var loggerA = hierarchy.LoggerFactory.CreateLogger(hierarchy, loggerName); loggerA.Hierarchy = hierarchy; loggerA.AddAppender(CreateFileAppender(loggerName, logFile, conversionPattern, maxSizeRollBackups, datePattern, maximumFileSize)); loggerA.Repository.Configured = true; loggerA.Level = Level.Debug; ILog logA = new LogImpl(loggerA); return(logA); }
public static ILog Setup(string logName, string logFilePath) { var hierarchy = (Hierarchy)LogManager.GetRepository(); hierarchy.Threshold = Level.Debug; // Configure logger var loggerRaw = hierarchy.LoggerFactory.CreateLogger(hierarchy, logName); loggerRaw.Hierarchy = hierarchy; loggerRaw.AddAppender(CreateFileAppender(logName, logFilePath)); loggerRaw.Repository.Configured = true; loggerRaw.Level = Level.Debug; ILog logger = new LogImpl(loggerRaw); return(logger); }
public void VerifyILoggerToILog() { // Arrange var repositoryMock = new Mock <ILoggerRepository>(); repositoryMock.Setup(m => m.LevelMap).Returns(new LevelMap()); var loggerMock = new Mock <log4net.Core.ILogger>(); loggerMock.Setup(m => m.IsEnabledFor(It.IsAny <Level>())).Returns(true); loggerMock.Setup(m => m.Repository).Returns(repositoryMock.Object); // Act var log = new LogImpl(loggerMock.Object); log.Debug("This is a test"); // Assert loggerMock.Verify(m => m.Log(It.IsAny <Type>(), It.IsAny <Level>(), It.IsAny <object>(), It.IsAny <Exception>()), Times.AtLeastOnce); }
public static void Dispose() { if (instance != null) { try { foreach (var item in instance.opcGrpsDic) { item.Value.Remove(false); } instance.opcSrv.Disconnect(); instance = null; } catch (Exception ex) { LogImpl.Error(string.Format("{0}{2}{1}", ex.StackTrace, ex.Message, System.Environment.NewLine)); } } }
private void CanExam(IAsyncResult result) { LogImpl.Debug("读卡成功"); AsyncResult ar = (AsyncResult)result; Func <IDCard, IDCard> md = (Func <IDCard, IDCard>)ar.AsyncDelegate; IDCard IC = md.EndInvoke(result); if (IC == null) { return; } ICCardBLL = new ICCardBLL { Name = IC.Name, Sex = IC.Sex, Nation = IC.Nation, Address = IC.Address, IDCode = IC.IDCode, }; }
public static ILog GetLogger(string name) { if (rootLogger == null || loggers == null) { Init(); } // No parent for root logger if (string.IsNullOrEmpty(name)) { return(rootLogger); } ILog log = null; if (loggers.TryGetValue(name, out log)) { return(log); } log = new LogImpl(name, null); loggers[name] = log; LogImpl parentLog = null; int i = name.LastIndexOf('.', name.Length - 1); if (i >= 0) { string parentName = name.Substring(0, i); parentLog = (LogImpl)GetLogger(parentName); } else { parentLog = rootLogger; } ((LogImpl)log).parent = parentLog; return(log); }
public bool SyncRead(GroupName enumGrp, ItemName enumItem, out bool iResult) { bool bExec; string strGrp = enumGrp.ToString(); int[] arrHandle = new int[] { opcResultsDic[strGrp][enumItem.ToString()].HandleServer }; OPCItemState[] arrState = new OPCItemState[1]; try { bExec = opcGrpsDic[strGrp].SyncRead(OPCDATASOURCE.OPC_DS_DEVICE, arrHandle, out arrState); } catch (Exception ee) { bExec = false; LogImpl.Debug("plc错误:" + ee.ToString()); } iResult = (bool)arrState[0].DataValue; return(bExec); }
private PLCCommand() { try { _opcSrv.Connect(StrSrvName); for (int i = 0; i < _arrGrps.Length; i++) { string strGrp = _arrGrps[i]; OpcGroup grp = _opcSrv.AddGroup(strGrp, true, 9600); grp.UpdateRate = 100; grp.Active = true; grp.PercentDeadband = 0; _opcGrpsDic.Add(strGrp, grp); string[] arrCurrentItems = _arrItems[i].Split(','); OPCItemDef[] opcItems = new OPCItemDef[arrCurrentItems.Length]; OPCItemResult[] opcResults = new OPCItemResult[arrCurrentItems.Length]; for (int j = 0; j < arrCurrentItems.Length; j++) { string strItemName = $"{StrItemId}.{strGrp}.{arrCurrentItems[j]}"; OPCItemDef item = new OPCItemDef(strItemName, true, opcResults.Length, System.Runtime.InteropServices.VarEnum.VT_BOOL); opcItems[j] = item; } Dictionary <string, OPCItemResult> oDic = new Dictionary <string, OPCItemResult>(); grp.AddItems(opcItems, out opcResults); for (int k = 0; k < opcResults.Length; k++) { oDic.Add(arrCurrentItems[k], opcResults[k]); } _opcResultsDic.Add(strGrp, oDic); } } catch (Exception ee) { LogImpl.Debug("错误" + ee.ToString()); } }
public void TestAdapterLogAdmin() { var mockAdmin = new MockAdminClient(null, "ADMIN"); var config = new StreamConfig(); config.ApplicationId = "test-logger-adapter"; var logger = new InMemoryLogger(); var log = new LogImpl(logger); var adapter = new KafkaLoggerAdapter(config, log); adapter.LogAdmin(mockAdmin, new Confluent.Kafka.LogMessage("error", Confluent.Kafka.SyslogLevel.Critical, "", "error")); Assert.AreEqual(1, logger.Logs.Count); logger.Logs.Clear(); adapter.ErrorAdmin(mockAdmin, new Confluent.Kafka.Error(Confluent.Kafka.ErrorCode.BrokerNotAvailable, "error")); Assert.AreEqual(1, logger.Logs.Count); logger.Logs.Clear(); }
private ILog CreateLogger() { // http://www.ronaldrosier.net/Blog/2013/05/11/create_a_log4net_logger_in_code var hierarchy = (Hierarchy)LogManager.GetRepository(); // since the current type is abstract, the inheriter's type is taken var logger = hierarchy.LoggerFactory.CreateLogger(hierarchy, this.GetType().FullName); logger.Hierarchy = hierarchy; hierarchy.AddRenderer(typeof(Exception), new ExceptionObjectLogger()); logger.AddAppender(this.CreateConsoleAppender()); logger.Repository.Configured = true; hierarchy.Threshold = Level.All; logger.Level = Level.All; ILog log = new LogImpl(logger); return(log); }
/// <summary> /// 初始化读卡器 /// </summary> private void InitReader() { iportAdr = int.Parse(System.Configuration.ConfigurationManager.AppSettings["DoorAdr"]); byte bytComAdr = 0x02; byte bytBaud = 0x5; try { Thread thread = new Thread(() => { int iResult = StaticClassReaderB.OpenComPort(iportAdr, ref bytComAdr, bytBaud, ref portOpenHandle); if (iResult == 0) { Inventory(); } }); thread.IsBackground = true; thread.Start(); } catch (Exception ex) { LogImpl.Error(string.Format("{0}{2}{1}", ex.StackTrace, ex.Message, System.Environment.NewLine)); } }
private PLCCommand2() { try { opcSrv.Connect(strSrvName); for (int i = 0; i < arrGrps.Length; i++) { string strGrp = arrGrps[i]; OpcGroup grp = opcSrv.AddGroup(strGrp, true, 9600); opcGrpsDic.Add(strGrp, grp); string[] arrCurrentItems = arrItems[i].Split(','); OPCItemDef[] opcItems = new OPCItemDef[arrCurrentItems.Length]; OPCItemResult[] opcResults = new OPCItemResult[arrCurrentItems.Length]; for (int j = 0; j < arrCurrentItems.Length; j++) { string strItemName = string.Format("{0}.{1}.{2}", strItemID, strGrp, arrCurrentItems[j]); OPCItemDef item = new OPCItemDef(strItemName, true, opcResults.Length, System.Runtime.InteropServices.VarEnum.VT_BOOL); opcItems[j] = item; } Dictionary <string, OPCItemResult> oDic = new Dictionary <string, OPCItemResult>(); grp.AddItems(opcItems, out opcResults); for (int k = 0; k < opcResults.Length; k++) { oDic.Add(arrCurrentItems[k], opcResults[k]); } opcResultsDic.Add(strGrp, oDic); } } catch (Exception ee) { LogImpl.Error("plc初始化:" + ee.StackTrace); } }
/** * @brief Send a game log to log server. * * @param logId Log Id. * @param detailId Detail Id. * @param pcSeq PCSeq. * @param logDataDic Log data dictionary. */ public static void SendGameLog(int logId, int detailId, string pcSeq, Dictionary <string, object> logDataDic) { Log.Debug("[Log] SendGameLog logId:" + logId + ", detailId:" + detailId + ", pcSeq:" + pcSeq + ", logDataDic:" + logDataDic); LogImpl.SendGameLog(logId, detailId, pcSeq, logDataDic); }
public SimpleLogManager() { var journal = new LogJournalImpl(); Log = new LogImpl(journal.Add); Journal = journal; }
private void button28_Click(object sender, EventArgs e) { LogImpl.Debug("temp"); }
public static void Init() { if( rootLogger == null ) rootLogger = new LogImpl("", LogLevel.Debug); if( loggers == null ) { loggers = new Dictionary<string, ILog>(); } }
public virtual LogImpl CreateLog(String actorId, EventType eventType) { LogImpl log = new LogImpl(actorId, DateTime.Now, eventType, this); if (_logs == null) { _logs = new ListSet(); } _logs.Add(log); return log; }
public static ILog GetLogger(string name) { if( rootLogger == null || loggers == null ) Init(); // No parent for root logger if( string.IsNullOrEmpty(name) ) return rootLogger; ILog log = null; if( loggers.TryGetValue(name, out log) ) return log; log = new LogImpl(name, null); loggers[name] = log; LogImpl parentLog = null; int i = name.LastIndexOf('.', name.Length-1); if( i >= 0 ) { string parentName = name.Substring(0, i); parentLog = (LogImpl)GetLogger(parentName); } else { parentLog = rootLogger; } ((LogImpl)log).parent = parentLog; return log; }
public void CreateLog(String actorId, EventType eventType) { this._logField = _flow.CreateLog(actorId, eventType); }
public void CreateLog(EventType eventType) { this._logField = _flow.CreateLog(eventType); }
private void button1_Click(object sender, RoutedEventArgs e) { LogImpl.Debug("测试"); }