public static void WriteMsg(MessageType degree, object obj, string strMsg, string strMark = "", Exception ex = null) { string strKey = (obj != null ? obj.GetType().FullName : "") + (string.IsNullOrEmpty(strMark) ? "" : " Mark:" + strMark); switch (degree) { case MessageType.DEBUG: logNet.WriteDebug(strKey, strMsg); break; case MessageType.ERROR: logNet.WriteError(strKey, strMsg); break; case MessageType.FATAL: logNet.WriteFatal(strKey, strMsg); break; case MessageType.INFO: logNet.WriteInfo(strKey, strMsg); break; case MessageType.NONE: logNet.WriteDescrition(strMsg); break; case MessageType.WARN: logNet.WriteWarn(strKey, strMsg); break; case MessageType.EXCEPTION: logNet.WriteException(strKey, ex); break; } }
private void button1_Click(object sender, EventArgs e) { string model = txtModel.Text.Trim(); string sql = string.Empty; if (string.IsNullOrEmpty(model)) { return; } curPath = path = Application.StartupPath + "\\HO-\\" + model + ".txt";// file = new LogNetSingle(path); if (String.IsNullOrEmpty(m_lastModel)) { m_lastModel = ConfigurationManager.AppSettings["LastModel676"]; sql = m_676.Replace(m_lastModel, model); m_lastModel = model; AppSetting.SetAppSettingValue("LastModel676", m_lastModel); } else { sql = m_676.Replace(m_lastModel, model); m_lastModel = model; AppSetting.SetAppSettingValue("LastModel676", m_lastModel); } file.WriteInfo(sql); }
/// <summary> /// 新增一个账户,如果账户名称已经存在,则返回False,注册成功返回True /// </summary> /// <param name="account">账户对象</param> /// <returns>成功<c>True</c>,失败<c>False</c></returns> public bool AddNewAccount(T account) { bool result = true; hybirdLock.Enter(); // 账户名重复的时候不允许添加 for (int i = 0; i < all_list_accounts.Count; i++) { if (all_list_accounts[i].UserName == account.UserName) { result = false; break; } } // 账户名为空的时候不允许添加 if (string.IsNullOrEmpty(account.UserName)) { result = false; } // 检测通过后进行添加账户名 if (result) { all_list_accounts.Add(account); ILogNet?.WriteInfo(SoftResources.StringResouce.AccountAddSuccess + account.UserName); } hybirdLock.Leave(); return(result); }
private void InitSocket() { try { if (!m_socketScan.Connected) { m_socketScan.Connect(endPoint); } m_scanRun = true; LogNetProgramer.WriteInfo("连接扫描枪成功!"); AddTips("连接扫描枪成功!"); } catch (Exception ex) { LogNetProgramer.WriteDebug("异常:" + ex.StackTrace + "--->" + ex.Message); MessageBox.Show(ex.Message); } }
private void ComplexServer_AcceptString(Communication.Core.Net.AppSession session, NetHandle handle, string data) { // 接收字符串 logNet.WriteInfo($"[{session.IpEndPoint}] [{handle}] {data}"); // 举个例子,当handle==1时,回发一串信息 // for example , when handle == 1. return text if (handle == 1) { complexServer.Send(session, handle, "This is test Text"); } }
/// <summary> /// 更新指定账户的密码 /// </summary> /// <param name="name"></param> /// <param name="password"></param> public void UpdatePassword(string name, string password) { hybirdLock.Enter(); for (int i = 0; i < all_list_accounts.Count; i++) { if (name == all_list_accounts[i].UserName) { all_list_accounts[i].Password = password; ILogNet?.WriteInfo(SoftResources.StringResouce.AccountModifyPassword + name); break; } } hybirdLock.Leave(); }
/// <summary> /// 更新指定账户的大小尺寸的头像MD5码 /// </summary> /// <param name="name"></param> /// <param name="largePortraitMD5">大尺寸头像的MD5</param> /// <param name="smallPortraitMD5">小尺寸头像的MD5</param> public void UpdatePortraitMD5(string name, string smallPortraitMD5, string largePortraitMD5) { hybirdLock.Enter(); for (int i = 0; i < all_list_accounts.Count; i++) { if (name == all_list_accounts[i].UserName) { all_list_accounts[i].SmallPortraitMD5 = smallPortraitMD5; all_list_accounts[i].LargePortraitMD5 = largePortraitMD5; ILogNet?.WriteInfo(SoftResources.StringResouce.AccountUploadPortrait + name); break; } } hybirdLock.Leave(); }
ILogNet logNetTime = new LogNetDateTime(Application.ResourceAssembly + "\\LogByTime", GenerateMode.ByEveryDay);//按每天 private void TestButton_Click(object sender, RoutedEventArgs e) { // 一般日志写入 logNet.WriteDebug("调试信息"); logNet.WriteInfo("一般信息"); logNet.WriteWarn("警告信息"); logNet.WriteError("错误信息"); logNet.WriteFatal("致命信息"); logNet.WriteException(null, new IndexOutOfRangeException()); // 带有关键字的写入,关键字建议为方法名或是类名,方便分析的时候归类搜索 logNet.WriteDebug("userButton1_Click", "调试信息"); logNet.WriteInfo("TestForm", "一般信息"); logNet.WriteWarn("随便什么", "警告信息"); logNet.WriteError("userButton1_Click", "错误信息"); logNet.WriteFatal("userButton1_Click", "致命信息"); logNet.WriteException("userButton1_Click", new IndexOutOfRangeException()); // 日志查看器 using (HslCommunication.LogNet.FormLogNetView form = new HslCommunication.LogNet.FormLogNetView()) { form.ShowDialog(); } }
/// <summary> /// 删除一个账户信息, /// </summary> /// <param name="name">需要删除的账户的名称</param> public void DeleteAccount(string name) { hybirdLock.Enter(); for (int i = 0; i < all_list_accounts.Count; i++) { if (name == all_list_accounts[i].UserName) { all_list_accounts.RemoveAt(i); ILogNet?.WriteInfo(SoftResources.StringResouce.AccountDeleteSuccess + name); break; } } hybirdLock.Leave(); }
static void Main() { //1.1.0 //HslControls.Authorization.SetAuthorizationCode("1557360d-6de4-445c-b669-dee903f02d4a"); //Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo("en"); //bool isCreateNew; //Mutex mutex = new Mutex(true, Application.ProductName, out isCreateNew); //if (isCreateNew) //{ Process process = Process.GetCurrentProcess(); // 遍历应用程序的同名进程组 foreach (Process p in Process.GetProcessesByName(process.ProcessName)) { // 不是同一进程则关闭刚刚创建的进程 if (p.Id != process.Id) { // 此处显示原先的窗口需要一定的时间,不然无法显示 ShowWindowAsync(p.MainWindowHandle, 9); SetForegroundWindow(p.MainWindowHandle); Application.Exit(); // 关闭当前的应用程序 return; } } ThreadPool.SetMaxThreads(2000, 256); Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); LogHelper.WriteLog("应用程序正常启动..."); LogHelper.WriteLog("Test...", LoggerType.ST010Logger); LogNet.WriteInfo("正常", "应用程序正常启动..."); //Application.Run(new SpotCheckForm()); Application.Run(new FormRedisService()); //} //else //{ // MessageBox.Show("应用程序已运行,请勿运行多个!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); // LogNet.WriteInfo("应用程序已运行,请勿运行多个!"); // Application.Exit(); //} }
private void ThreadLogTest() { DateTime start = DateTime.Now; for (int i = 0; i < 1000000; i++) { logNet.WriteInfo("key", "这是一条测试日志"); } TimeSpan ts = DateTime.Now - start; Invoke(new Action(() => { MessageBox.Show("完成!耗时:" + ts.TotalMilliseconds.ToString("F3")); button3.Enabled = true; })); }
public void logWriteInfo(string data) { logNet.WriteInfo(data); }
/// <summary> /// 日志信息 /// </summary> /// <param name="command"></param> public void Info(string command) { //生成日志 LogRecord.WriteInfo(command); }
/// <summary> /// 读取Glassinfo,参数Filename,不含后缀 /// </summary> /// <param name="filepath"></param> public static void ReadGlassInfo(string fileName) { SysPara.GlassInfos.Clear(); SysPara.GlassInfos = new List <GlassInfo>(); if (SysPara.SourcePath == "Not Config") { //MessageBox.Show("Please config the Retrieving Source Catalogue!"); //MessageBox.Show("Please config the Source Path!"); MessageBox.Show("Please config the Source Path!", "Tips", MessageBoxButtons.OK, MessageBoxIcon.None, MessageBoxDefaultButton.Button1, MessageBoxOptions.ServiceNotification); return; } string filePath = GlassInfoPath + fileName + ".dat"; FileInfo fileInfo = new FileInfo(filePath); if (!Directory.Exists(fileInfo.DirectoryName)) { Directory.CreateDirectory(fileInfo.DirectoryName); LogNet.WriteInfo("ReadGlassInfo():Create Directory!"); } if (File.Exists(filePath)) { SysPara.GlassInfos = (List <GlassInfo>)CommonMethod.GetDataFromFile(filePath); } //扫描文件目录 string SearchPath = SysPara.SourcePath + "\\" + fileName; List <DirectoryInfo> GlassIDListDirectory = CommonMethod.GetFilePath(SearchPath); List <FileInfo> GlassIDCsvList = CommonMethod.GetFile(SearchPath, TextSuffix); //提取数据 if (SysPara.GlassInfos.Count != GlassIDListDirectory.Count)//数据不相等 { foreach (var o in GlassIDListDirectory) { if (SysPara.GlassInfos.Count <= 0 || SysPara.GlassInfos.Where(p => p.DirName == o.Name).ToList().Count <= 0) { //时间判断 if ((DateTime.Now - o.CreationTime).Minutes < OverTime) { continue; } //初始化数据 GlassInfo glassInfo = new GlassInfo(); //提取ID string tmpID = o.Name; int index = tmpID.IndexOf("TB"); if (index != -1) { tmpID = tmpID.Remove(0, index + 2); } glassInfo.Id = tmpID; //提取EQID,Point坐标 FileInfo textInfo = GlassIDCsvList.Where(p => p.Name.Contains(tmpID)).FirstOrDefault(); if (textInfo != null) { StreamReader sr = new StreamReader(textInfo.FullName); int iLnTmp = 0; //记录文件行数 string sTmp = ""; //读取的数据 while (!sr.EndOfStream && iLnTmp <= Point4Line + 1) //不为最后一行,且小于要读的最后的行数 { iLnTmp++; sTmp = sr.ReadLine(); //读取当前行 //设备ID if (iLnTmp == ReadEQLine) { glassInfo.Equip00_ID = GetLastStr(sTmp, ','); glassInfo.Equip01_ID = glassInfo.Equip00_ID; continue; } //Point1 if (iLnTmp == Point1Line) { glassInfo.Point1.X = GetLastStr(sTmp, ','); continue; } if (iLnTmp == Point1Line + 1) { glassInfo.Point1.Y = GetLastStr(sTmp, ','); continue; } //Point2 if (iLnTmp == Point2Line) { glassInfo.Point2.X = GetLastStr(sTmp, ','); continue; } if (iLnTmp == Point2Line + 1) { glassInfo.Point2.Y = GetLastStr(sTmp, ','); continue; } //Point3 if (iLnTmp == Point3Line) { glassInfo.Point3.X = GetLastStr(sTmp, ','); continue; } if (iLnTmp == Point3Line + 1) { glassInfo.Point3.Y = GetLastStr(sTmp, ','); continue; } //Point4 if (iLnTmp == Point4Line) { glassInfo.Point4.X = GetLastStr(sTmp, ','); continue; } if (iLnTmp == Point4Line + 1) { glassInfo.Point4.Y = GetLastStr(sTmp, ','); continue; } } sr.Close(); } //记录文件目录 glassInfo.DirName = o.Name; //添加数据 SysPara.GlassInfos.Add(glassInfo); //{ // Id = tmpID, // DirName = o.Name, // CreateTime = o.CreationTime.ToString("yyyyMMdd hh:ss"), // Equip00_ID = "", // Equip01_ID = "", // Point1 = new SheetShift(0, 0), // Point2 = new SheetShift(0, 0), // Point3 = new SheetShift(0, 0), // Point4 = new SheetShift(0, 0) //}); } } } }
public static void WriteLog(string title, string info) { LogNet.WriteInfo(title, info); }