添加编译指令

This commit is contained in:
gongxh
2022-01-18 20:20:10 +08:00
parent a7ef9c7b54
commit 89f1bb0536
5 changed files with 707 additions and 640 deletions

View File

@@ -36,6 +36,14 @@ namespace NX_LogUtility
}
public static class LogHelper
{
private readonly static System.Collections.Concurrent.BlockingCollection<string> messages = new System.Collections.Concurrent.BlockingCollection<string>();
#region 记录日志为文本文档形式
/// <summary>
/// 记录日志类
@@ -75,47 +83,54 @@ namespace NX_LogUtility
Task.Run(() =>
{
#if !DEBUG
try
{
lock (lockobj)
#endif
lock (lockobj)
{
if (!Directory.Exists(strDir))//如果日志文件存放的文件夹不存在,就新建一个文件夹。
{
if (!Directory.Exists(strDir))//如果日志文件存放的文件夹不存在,就新建一个文件夹。
{
Directory.CreateDirectory(strDir);
}
if (File.Exists(filePath))//日志文件存放路径存在,向日志文件追加记录。
{
fs = new FileStream(filePath, FileMode.Append);
}
else//日志文件存放路径不存在,创建日志文件。
{
fs = new FileStream(filePath, FileMode.Create);
}
sw = new StreamWriter(fs);
//开始写入
sw.Write(txt);
//清空缓冲区
sw.Flush();
//关闭流
sw.Close();
fs.Close();
Directory.CreateDirectory(strDir);
}
if (File.Exists(filePath))//日志文件存放路径存在,向日志文件追加记录。
{
fs = new FileStream(filePath, FileMode.Append);
}
else//日志文件存放路径不存在,创建日志文件。
{
fs = new FileStream(filePath, FileMode.Create);
}
sw = new StreamWriter(fs);
//开始写入
sw.Write(txt);
//清空缓冲区
sw.Flush();
//关闭流
sw.Close();
fs.Close();
}
#if !DEBUG
}
catch (Exception)
{
;
}
finally
{
if (sw != null)
sw.Close();
if (fs != null)
fs.Close();
#endif
if (sw != null)
sw.Close();
if (fs != null)
fs.Close();
#if !DEBUG
}
#endif
});