8 changed files with 86 additions and 64 deletions
@ -0,0 +1,36 @@ |
|||||
|
using System; |
||||
|
using System.Collections.Generic; |
||||
|
using System.IO; |
||||
|
using System.Linq; |
||||
|
using System.Text; |
||||
|
using System.Threading.Tasks; |
||||
|
|
||||
|
namespace formula_manage.UserClass |
||||
|
{ |
||||
|
public class LogGing |
||||
|
{ |
||||
|
public static void LogGingDATA(string dat) |
||||
|
{ |
||||
|
string logpath = System.Environment.CurrentDirectory + "\\Log";//日志文件目录
|
||||
|
string logPath = "" + System.Environment.CurrentDirectory + "\\Log\\"+ DateTime.Now.ToString("yyyy-MM-dd") + ".txt";//日志文件
|
||||
|
string Log_time = "[" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "]:"; |
||||
|
|
||||
|
System.IO.DirectoryInfo log = new System.IO.DirectoryInfo(@logpath);//生成日志文件目录
|
||||
|
if (!File.Exists(logPath))//检查日志文件并写入启动日志
|
||||
|
{ |
||||
|
FileStream fs = new FileStream(logPath, FileMode.CreateNew, FileAccess.Write);//创建写入文件
|
||||
|
StreamWriter wr = new StreamWriter(fs);//创建文件
|
||||
|
wr.WriteLine(Log_time + dat); |
||||
|
wr.Close(); |
||||
|
} |
||||
|
else |
||||
|
{ |
||||
|
FileStream fs = new FileStream(logPath, FileMode.Append, FileAccess.Write); |
||||
|
StreamWriter wr = new StreamWriter(fs);//创建文件
|
||||
|
wr.WriteLine(Log_time + dat); |
||||
|
wr.Close(); |
||||
|
} |
||||
|
|
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,33 @@ |
|||||
|
using System; |
||||
|
using System.Collections.Generic; |
||||
|
using System.Linq; |
||||
|
using System.Net.Sockets; |
||||
|
using System.Net; |
||||
|
using System.Text; |
||||
|
using System.Threading.Tasks; |
||||
|
using System.Net.NetworkInformation; |
||||
|
|
||||
|
namespace formula_manage.UserClass |
||||
|
{ |
||||
|
public class get_local_ip_address |
||||
|
{ |
||||
|
public static string getLocalIPAddressWithNetworkInterface(NetworkInterfaceType _type)//获取本机ip并以字符串方式返回
|
||||
|
{ |
||||
|
string output = ""; |
||||
|
foreach (NetworkInterface item in NetworkInterface.GetAllNetworkInterfaces()) |
||||
|
{ |
||||
|
if (item.NetworkInterfaceType == _type && item.OperationalStatus == OperationalStatus.Up) |
||||
|
{ |
||||
|
foreach (UnicastIPAddressInformation ip in item.GetIPProperties().UnicastAddresses) |
||||
|
{ |
||||
|
if (ip.Address.AddressFamily == AddressFamily.InterNetwork) |
||||
|
{ |
||||
|
output = ip.Address.ToString(); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
return output; |
||||
|
} |
||||
|
} |
||||
|
} |
||||
Loading…
Reference in new issue