private static void defaultOutput(LogData data, string path) { var log = data.ToString(); if (TheBaseAssets.MySYSLOG != null) { var msgLevel = eMsgLevel.l4_Message; var debugLevel = eDEBUG_LEVELS.FULLVERBOSE; switch (data.Level) { case LogLevel.Error: case LogLevel.Fatal: msgLevel = eMsgLevel.l1_Error; debugLevel = eDEBUG_LEVELS.OFF; break; case LogLevel.Warn: msgLevel = eMsgLevel.l2_Warning; debugLevel = eDEBUG_LEVELS.OFF; break; case LogLevel.Info: msgLevel = eMsgLevel.l4_Message; debugLevel = eDEBUG_LEVELS.VERBOSE; break; case LogLevel.Debug: msgLevel = eMsgLevel.l6_Debug; debugLevel = eDEBUG_LEVELS.VERBOSE; break; case LogLevel.Trace: msgLevel = eMsgLevel.l6_Debug; debugLevel = eDEBUG_LEVELS.FULLVERBOSE; break; } TheBaseAssets.MySYSLOG?.WriteToLog(4365, TSM.L(debugLevel) ? null : new TSM("WebSocketSharp", "WebSocketSharp", msgLevel, log)); } else { TheSystemMessageLog.ToCo(log); } if (path != null && path.Length > 0) { writeToFile(log, path); } }
private void output(string message, LogLevel level) { lock (_sync) { if (_level > level) { return; } LogData data = null; try { data = new LogData(level, new StackFrame(2, true), message); _output(data, _file); } catch (Exception ex) { data = new LogData(LogLevel.Fatal, new StackFrame(0, true), ex.Message); TheSystemMessageLog.ToCo(data.ToString()); } } }
public bool Init() { if (mIsInitCalled) { return(false); } mIsInitCalled = true; MyBaseThing.StatusLevel = 1; MyBaseThing.Version = TheBaseAssets.MyAppInfo.CurrentVersion.ToString(CultureInfo.InvariantCulture); MyBaseThing.Capabilities = TheBaseAssets.MyAppInfo.Capabilities; MyBaseThing.Address = TheBaseAssets.MyServiceHostInfo.GetPrimaryStationURL(false); TheThing.SetSafePropertyString(MyBaseThing, "Description", TheBaseAssets.MyAppInfo.LongDescription); mIsInitialized = true; TheThing.SetSafePropertyBool(MyBaseThing, "EnableKPIs", TheCommonUtils.CBool(TheBaseAssets.MySettings.GetSetting("EnableKPIs"))); if (TheBaseAssets.MyServiceHostInfo.EnableTaskKPIs) { var taskKpiThread = new System.Threading.Thread(() => { TheSystemMessageLog.ToCo($"Tasks {DateTime.Now}: NodeHost starting Task KPI thread"); do { Thread.Sleep(1000); // Keeping it simple here, to minimize interference on task scheduler/thread scheduler etc. (Assumption: not used on production systems) // TheCommonUtils.SleepOneEye(1000, 1000); var kpis = TheCommonUtils.GetTaskKpis(null); TheSystemMessageLog.ToCo($"Tasks {DateTime.Now}: {TheCommonUtils.SerializeObjectToJSONString(kpis)}"); } while (TheBaseAssets.MasterSwitch && TheBaseAssets.MyServiceHostInfo.EnableTaskKPIs); TheSystemMessageLog.ToCo($"Tasks {DateTime.Now}: NodeHost ending Task KPI thread"); }); taskKpiThread.Start(); } KPIHarvestInterval = TheCommonUtils.CInt(TheBaseAssets.MySettings.GetAppSetting("KPIHarvestIntervalInSeconds", "5", false, true)); if (KPIHarvestInterval > 0) { TheQueuedSenderRegistry.RegisterHealthTimer(sinkCyclic); } return(true); }
public void Print(bool dumped) { TheSystemMessageLog.ToCo(dumped ? dump(this) : print(this)); }
internal static bool GetLocalIPs(bool AddLoopBack) { bool NewAddition = false; bool HasLoop = false; if ((Type.GetType("Mono.Runtime") != null)) { try { if (string.IsNullOrEmpty(MyHostName)) { MyHostName = cdeGetHostName(); } IPHostEntry hostByName = cdeGetHostEntry(MyHostName); if (hostByName == null) { return(false); } TheSystemMessageLog.ToCo(string.Format("NetworkInfo - HostName : {0}", hostByName.HostName)); ArrayList tAddressTable = new ArrayList(hostByName.AddressList); foreach (IPAddress address in tAddressTable) { if (address.AddressFamily != AddressFamily.InterNetworkV6) { NewAddition = true; byte[] ipAdressBytes = address.GetAddressBytes(); TheIPDef tI = new TheIPDef() { ipAdressBytes = ipAdressBytes, SubnetBytes = new byte[] { 255, 0, 0, 0 }, IPAddr = address, IsDnsEnabled = true, IsPrivateIP = IsPrivateIPBytes(ipAdressBytes) }; if (address.ToString().Equals(IPAddress.Loopback.ToString())) { HasLoop = true; tI.IsLoopBack = true; } AddressTable.TryAdd(address, tI); } } //TheSystemMessageLog.ToCo($"NetworkInfo - AddressTable : {AddressTable.Aggregate("", (s, a) => $"{s} {a}")}"); } catch (Exception e) { TheSystemMessageLog.ToCo($"NetworkInfo - Exception: {e.ToString()}"); // throw; } } else { NetworkInterface[] networkInterfaces; try { networkInterfaces = NetworkInterface.GetAllNetworkInterfaces(); } catch { networkInterfaces = null; } if (networkInterfaces != null) { foreach (var f in networkInterfaces) { var ipInterface = f.GetIPProperties(); foreach (UnicastIPAddressInformation unicastAddress in ipInterface.UnicastAddresses) { try { if (unicastAddress.IPv4Mask != null) { IPv4InterfaceProperties ipv4_properties = null; try { ipv4_properties = ipInterface.GetIPv4Properties(); } catch { //ignored } if (ipv4_properties == null) { continue; //TODO: IPv6 Support later } byte[] tSubnetBytes = unicastAddress.IPv4Mask.GetAddressBytes(); if (tSubnetBytes[0] == 0) { continue; } byte[] ipAdressBytes = unicastAddress.Address.GetAddressBytes(); IPAddress tIP = new IPAddress(ipAdressBytes); if (!AddressTable.ContainsKey(tIP)) { TheIPDef tI = new TheIPDef() { ipAdressBytes = ipAdressBytes, SubnetBytes = tSubnetBytes, IPAddr = tIP, //IsDnsEnabled = unicastAddress.IsDnsEligible, IsPrivateIP = IsPrivateIPBytes(ipAdressBytes), NetworkInterfaceIndex = ipv4_properties.Index, MACAddress = f.GetPhysicalAddress().ToString(), }; if (!_platformDoesNotSupportUnicastIPAddressInformationIsDNSEnabled) { try { tI.IsDnsEnabled = unicastAddress.IsDnsEligible; } catch (PlatformNotSupportedException) { _platformDoesNotSupportUnicastIPAddressInformationIsDNSEnabled = true; } } if (_platformDoesNotSupportUnicastIPAddressInformationIsDNSEnabled) { if (string.IsNullOrEmpty(MyHostName)) { MyHostName = cdeGetHostName(); } var ipAddresses = cdeGetHostEntry(MyHostName)?.AddressList; if (ipAddresses?.FirstOrDefault(ip => ip.Equals(unicastAddress.Address)) != null) { tI.IsDnsEnabled = true; } } if (tIP.ToString().Equals(IPAddress.Loopback.ToString())) { HasLoop = true; tI.IsLoopBack = true; } AddressTable.TryAdd(tIP, tI); NewAddition = true; } } } catch { } } } } } if (AddLoopBack && !HasLoop) { AddressTable.TryAdd(IPAddress.Loopback, new TheIPDef() { IPAddr = IPAddress.Loopback, ipAdressBytes = IPAddress.Loopback.GetAddressBytes(), SubnetBytes = new byte[] { 255, 0, 0, 0 }, IsPrivateIP = true, IsDnsEnabled = false, IsLoopBack = true }); NewAddition = true; } return(NewAddition); }