自定義日誌記錄檔案

2021-04-13 23:09:43 字數 2135 閱讀 2506

舉例:郵件傳送錯誤記錄日誌

日誌記錄介面:(ilogservice.cs)

public inte***ce ilogservice

日誌記錄介面(實現):(filelogservice.cs)

public class filelogservice : ilogservice

finally

}catch}}

#endregion

}傳送郵件的介面:

public class mailserviceimpl : imailservice

this link will expire in 24 hour.", resetlink, resetlink);

string strsubject = "reset password link";

//傳送郵件

client = new **tpclient(**tpserver);

client.usedefaultcredentials = false;

client.credentials = new system.net.networkcredential(mailusername, mailpassword);

client.deliverymethod = **tpdeliverymethod.network;

mailmessage mailmessage = new mailmessage(strfrom, strto, strsubject, strbody);

mailmessage.bodyencoding = system.text.encoding.utf8;

mailmessage.isbodyhtml = true;

client.send(mailmessage);

return true;

}catch (exception ex)

}private void logexception(exception ex)

/r/n", ex.message, ex.stacktrace);

servicelocator.logservice.write(msg);}

///

/// 修改密碼後發郵件

///

///

///

///

public bool sendsetpasswordsucessflymail(string receiveemail, string username, string newpassword)

catch (exception ex)

}///

/// 反饋發郵件

///

///

///

///

public bool sendfeedbackmail(string sendemail, string subject, string content)

feedback: ", sendemail, content);

string strsubject = "gis portal feedback: " + subject;

//傳送郵件

client = new **tpclient(**tpserver);

client.usedefaultcredentials = false;

client.credentials = new system.net.networkcredential(mailusername, mailpassword);

client.deliverymethod = **tpdeliverymethod.network;

mailmessage mailmessage = new mailmessage(strfrom, strto, strsubject, strbody);

mailmessage.bodyencoding = system.text.encoding.utf8;

mailmessage.isbodyhtml = true;

client.send(mailmessage);

return true;

}catch (exception ex)

}#endregion

Yii 記錄日誌到自定義檔案

日誌格式如下 時間 級別 類別 內容 但有時候需要把某些特定的日誌放到特定的檔案中,比如交易失敗的日誌,需要和其他日誌區分開來單獨記錄。在yii中可以通過配置不同的clogrouter來解決。你需要先了解yii的日誌機制,yii的日誌功能有clogger和clogrouter兩部分,其中clogge...

自定義日誌檔案

借用 部落格 usr bin python coding utf 8 importlogging importos.path importtime 自定義日誌類 classlogger object def init self,logger 指定儲存日誌的檔案路徑,日誌級別,以及呼叫檔案 將日誌存入...

storm 自定義 日誌檔案

storm中的日誌級級別預設為info,並且,日誌檔案是根據worker號來進行區分的,這樣,同乙個log檔案中的資訊不一定是乙個業務的,這樣就會有以下兩個需求出現 1.想要進行一些除錯資訊的輸出 2.除錯資訊或者業務日誌資訊想要輸出到一些固定的檔案中 不要怕,不要煩惱,其實storm已經提供了這樣...