|  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | #endregion | 
|---|
|  |  |  |  | 
|---|
|  |  |  | #region 自定义文件名 | 
|---|
|  |  |  | public static void CustomWriteLog(object obj, string FileName, string filePath = "Vlog" , bool isAppend = true) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | try | 
|---|
|  |  |  | { | 
|---|
|  |  |  | lock (lockObj) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | filePath = $@"{filePath}\{FileName}.txt"; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | filePath = AppDomain.CurrentDomain.BaseDirectory + filePath; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | if (!System.IO.Directory.Exists(Path.GetDirectoryName(filePath))) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | System.IO.Directory.CreateDirectory(Path.GetDirectoryName(filePath)); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | bool fileExists = System.IO.File.Exists(filePath); | 
|---|
|  |  |  | //不存在 则创建该文件 | 
|---|
|  |  |  | if (!fileExists) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | System.IO.File.Create(filePath).Close(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | using (StreamWriter writer = new StreamWriter(filePath, isAppend)) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | //存在的时候才写一行 | 
|---|
|  |  |  | if (fileExists && isAppend) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | writer.WriteLine(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | var content = obj is string ? obj : JsonConvert.SerializeObject(obj); | 
|---|
|  |  |  | writer.WriteLine($"{DateTime.Now} {content}"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | catch (Exception ex) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | #endregion | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|