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; } }
/// <summary> /// 使用用户自定义的解密方法从文件读取数据 /// </summary> /// <param name="decrypt">用户自定义的解密方法</param> public void LoadByFile(Converter <string, string> decrypt) { if (FileSavePath != "") { if (File.Exists(FileSavePath)) { HybirdLock.Enter(); try { using (StreamReader sr = new StreamReader(FileSavePath, Encoding.Default)) { LoadByString(decrypt(sr.ReadToEnd())); } } catch (Exception ex) { ILogNet?.WriteException(StringResources.FileLoadFailed, ex); } finally { HybirdLock.Leave(); } } } }
private void button7_Click(object sender, EventArgs e) { try { int i = 0; int j = 100 / i; } catch (Exception ex) { logNet.WriteException(textBox1.Text, ex); } }
/// <summary> /// 从所有的账户的json数据加载账户 /// </summary> /// <param name="json"></param> public void LoadAllAccountsJson(string json) { hybirdLock.Enter(); try { all_list_accounts = JArray.Parse(json).ToObject <List <T> >(); } catch (Exception ex) { ILogNet?.WriteException(SoftResources.StringResouce.AccountLoadFailed, ex); } 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> public void LeaveReadOperator( ) { // 检查文件标记状态 hybirdLock.Enter( ); readStatus--; if (readStatus == 0) { while (queues.Count > 0) { try { queues.Dequeue( )?.Invoke( ); } catch (Exception ex) { LogNet?.WriteException("FileMarkId", "File Action Failed:", ex); } } } hybirdLock.Leave( ); }
/// <summary> /// 使用用户自定义的加密方法保存数据到文件 /// </summary> /// <param name="encrypt">用户自定义的加密方法</param> public void SaveToFile(Converter <string, string> encrypt) { if (FileSavePath != "") { HybirdLock.Enter(); try { using (StreamWriter sw = new StreamWriter(FileSavePath, false, Encoding.Default)) { sw.Write(encrypt(ToSaveString())); sw.Flush(); } } catch (Exception ex) { ILogNet?.WriteException(StringResources.FileSaveFailed, ex); } finally { HybirdLock.Leave(); } } }