I want to check the size of text file i.e. if the file size is greater then 500kb then create another file with numbers.
Example:
Currently my file is saved like : NetApiLog_2019_04_25.txt
Here is the code to save file-
- public void writeLogFile(string errorln)
- {
- FileStream fs = null;
- try
- {
- var common = (ICommon)new CommonAttribute();
- var netVpbxApiLogFlag = common.GetConfigurationByKeyName(string.Empty, "NetVpbxApiLogFlag");
- if (Convert.ToBoolean(netVpbxApiLogFlag))
- {
- var logFilePath = common.GetConfigurationByKeyName(string.Empty, "NetApiLogFilePath");
- string FileName = string.Format("{0}_{1}.txt", logFilePath,
- DateTime.Today.ToString("yyyy_MM_dd"));
-
- if (!Directory.Exists(logFilePath))
- {
- Directory.CreateDirectory(logFilePath);
- }
-
- fs = new FileStream(FileName, FileMode.Append, FileAccess.Write);
- using (StreamWriter sw = new StreamWriter(fs))
- {
- fs = null;
- sw.WriteLine("Start VPBX Api.");
- sw.WriteLine("-------------------------------------------------------");
- sw.WriteLine(string.Format("{0}:{1}", DateTime.Now.ToString(), errorln));
- }
- }
- }
- catch (Exception ex)
- {
- throw ex;
- }
- finally
- {
- if (fs != null)
- {
- fs.Dispose();
- }
- }
- }
If the file size is greater then 500kb then create the file like :
NetApiLog_1_2019_04_25.txt
if the size of file text file NetApiLog_1_2019_04_25.txt greater then 500 kb then the name should be NetApiLog_2_2019_04_25.txt.
Can anyone help me to how to write in c# asp .net.??