-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
17 changed files
with
1,993 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
################################################################################ | ||
# 此 .gitignore 文件已由 Microsoft(R) Visual Studio 自动创建。 | ||
################################################################################ | ||
|
||
/PrimeNumber/bin/Debug | ||
/PrimeNumber/obj/Debug | ||
/.vs/PrimeNumber |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
|
||
Microsoft Visual Studio Solution File, Format Version 12.00 | ||
# Visual Studio Version 17 | ||
VisualStudioVersion = 17.5.33502.453 | ||
MinimumVisualStudioVersion = 10.0.40219.1 | ||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PrimeNumber", "PrimeNumber\PrimeNumber.csproj", "{4DE1916E-3164-4A40-8935-3FD3CAB9216D}" | ||
EndProject | ||
Global | ||
GlobalSection(SolutionConfigurationPlatforms) = preSolution | ||
Debug|Any CPU = Debug|Any CPU | ||
Release|Any CPU = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(ProjectConfigurationPlatforms) = postSolution | ||
{4DE1916E-3164-4A40-8935-3FD3CAB9216D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
{4DE1916E-3164-4A40-8935-3FD3CAB9216D}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
{4DE1916E-3164-4A40-8935-3FD3CAB9216D}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
{4DE1916E-3164-4A40-8935-3FD3CAB9216D}.Release|Any CPU.Build.0 = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(SolutionProperties) = preSolution | ||
HideSolutionNode = FALSE | ||
EndGlobalSection | ||
GlobalSection(ExtensibilityGlobals) = postSolution | ||
SolutionGuid = {FEA967DF-C1FE-4D62-8F8F-CA44F04C6502} | ||
EndGlobalSection | ||
EndGlobal |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<?xml version="1.0" encoding="utf-8" ?> | ||
<configuration> | ||
<startup> | ||
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" /> | ||
</startup> | ||
</configuration> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,120 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<root> | ||
<!-- | ||
Microsoft ResX Schema | ||
Version 2.0 | ||
The primary goals of this format is to allow a simple XML format | ||
that is mostly human readable. The generation and parsing of the | ||
various data types are done through the TypeConverter classes | ||
associated with the data types. | ||
Example: | ||
... ado.net/XML headers & schema ... | ||
<resheader name="resmimetype">text/microsoft-resx</resheader> | ||
<resheader name="version">2.0</resheader> | ||
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader> | ||
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader> | ||
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data> | ||
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data> | ||
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64"> | ||
<value>[base64 mime encoded serialized .NET Framework object]</value> | ||
</data> | ||
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64"> | ||
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value> | ||
<comment>This is a comment</comment> | ||
</data> | ||
There are any number of "resheader" rows that contain simple | ||
name/value pairs. | ||
Each data row contains a name, and value. The row also contains a | ||
type or mimetype. Type corresponds to a .NET class that support | ||
text/value conversion through the TypeConverter architecture. | ||
Classes that don't support this are serialized and stored with the | ||
mimetype set. | ||
The mimetype is used for serialized objects, and tells the | ||
ResXResourceReader how to depersist the object. This is currently not | ||
extensible. For a given mimetype the value must be set accordingly: | ||
Note - application/x-microsoft.net.object.binary.base64 is the format | ||
that the ResXResourceWriter will generate, however the reader can | ||
read any of the formats listed below. | ||
mimetype: application/x-microsoft.net.object.binary.base64 | ||
value : The object must be serialized with | ||
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter | ||
: and then encoded with base64 encoding. | ||
mimetype: application/x-microsoft.net.object.soap.base64 | ||
value : The object must be serialized with | ||
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter | ||
: and then encoded with base64 encoding. | ||
mimetype: application/x-microsoft.net.object.bytearray.base64 | ||
value : The object must be serialized into a byte array | ||
: using a System.ComponentModel.TypeConverter | ||
: and then encoded with base64 encoding. | ||
--> | ||
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata"> | ||
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" /> | ||
<xsd:element name="root" msdata:IsDataSet="true"> | ||
<xsd:complexType> | ||
<xsd:choice maxOccurs="unbounded"> | ||
<xsd:element name="metadata"> | ||
<xsd:complexType> | ||
<xsd:sequence> | ||
<xsd:element name="value" type="xsd:string" minOccurs="0" /> | ||
</xsd:sequence> | ||
<xsd:attribute name="name" use="required" type="xsd:string" /> | ||
<xsd:attribute name="type" type="xsd:string" /> | ||
<xsd:attribute name="mimetype" type="xsd:string" /> | ||
<xsd:attribute ref="xml:space" /> | ||
</xsd:complexType> | ||
</xsd:element> | ||
<xsd:element name="assembly"> | ||
<xsd:complexType> | ||
<xsd:attribute name="alias" type="xsd:string" /> | ||
<xsd:attribute name="name" type="xsd:string" /> | ||
</xsd:complexType> | ||
</xsd:element> | ||
<xsd:element name="data"> | ||
<xsd:complexType> | ||
<xsd:sequence> | ||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" /> | ||
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" /> | ||
</xsd:sequence> | ||
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" /> | ||
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" /> | ||
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" /> | ||
<xsd:attribute ref="xml:space" /> | ||
</xsd:complexType> | ||
</xsd:element> | ||
<xsd:element name="resheader"> | ||
<xsd:complexType> | ||
<xsd:sequence> | ||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" /> | ||
</xsd:sequence> | ||
<xsd:attribute name="name" type="xsd:string" use="required" /> | ||
</xsd:complexType> | ||
</xsd:element> | ||
</xsd:choice> | ||
</xsd:complexType> | ||
</xsd:element> | ||
</xsd:schema> | ||
<resheader name="resmimetype"> | ||
<value>text/microsoft-resx</value> | ||
</resheader> | ||
<resheader name="version"> | ||
<value>2.0</value> | ||
</resheader> | ||
<resheader name="reader"> | ||
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value> | ||
</resheader> | ||
<resheader name="writer"> | ||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value> | ||
</resheader> | ||
</root> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,228 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.IO; | ||
using System.Linq; | ||
using System.Reflection; | ||
using System.Web; | ||
|
||
namespace PrimeNumber.Helper | ||
{ | ||
public class LogHelper | ||
{ | ||
static string assemblyDirPath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); | ||
|
||
/// <summary> | ||
/// 创建文件夹 | ||
/// </summary> | ||
/// <param name="path">文件夹路径</param> | ||
/// <returns></returns> | ||
public static bool CreateFolder(string path) | ||
{ | ||
//try | ||
//{ | ||
|
||
//目录已存在等同于创建成功处理 | ||
if (Directory.Exists(path.Trim('\\'))) | ||
{ | ||
return true; | ||
} | ||
else | ||
{ | ||
//创建文件夹 | ||
DirectoryInfo dirInfo = Directory.CreateDirectory(path); | ||
return true; | ||
} | ||
//} | ||
//catch (Exception ex) | ||
//{ | ||
// Console.WriteLine(ex.Message); | ||
// return false; | ||
//} | ||
} | ||
|
||
/// <summary> | ||
/// //创建文件 | ||
/// </summary> | ||
/// <param name="path">path 文件路径</param> | ||
public static void CreateFile(string path) | ||
{ | ||
//try | ||
//{ | ||
if (CreateFolder(path.Substring(0, path.LastIndexOf("\\")))) | ||
{ | ||
if (!File.Exists(path)) | ||
{ | ||
FileStream fs = File.Create(path); | ||
fs.Close(); | ||
} | ||
} | ||
//} | ||
//catch (Exception ex) | ||
//{ | ||
// Console.WriteLine(ex.Message); | ||
// return; | ||
//} | ||
} | ||
|
||
/// <summary> | ||
/// 删除文件 | ||
/// </summary> | ||
/// <param name="path"></param> | ||
public void DeleteFile(string path) | ||
{ | ||
if (File.Exists(path)) | ||
{ | ||
File.Delete(path); | ||
} | ||
} | ||
|
||
/// <summary> | ||
/// 写文件 | ||
/// </summary> | ||
/// <param name="path">文件路径</param> | ||
/// <param name="content">文本内容</param> | ||
public static void WriteFile(string path, string content) | ||
{ | ||
try | ||
{ | ||
if (!File.Exists(path)) | ||
CreateFile(path); | ||
|
||
using (FileStream fs = new FileStream(path, FileMode.Append, FileAccess.Write)) | ||
using (StreamWriter sw = new StreamWriter(fs)) | ||
{ | ||
sw.WriteLine(content); | ||
sw.Close(); | ||
fs.Close(); | ||
} | ||
} | ||
catch (Exception ex) | ||
{ | ||
Console.WriteLine(ex.Message); | ||
return; | ||
} | ||
} | ||
|
||
/// <summary> | ||
/// 将即时日志保存入日志文件(asp.net WebForm) | ||
/// </summary> | ||
//public static void WriteAppDataLog(string content) | ||
//{ | ||
// //string assemblyDirPath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); | ||
// string assemblyDirPath = HttpRuntime.AppDomainAppPath.ToString(); | ||
|
||
// string logPath = assemblyDirPath + "\\App_Data\\Log"; | ||
// string logName = string.Format("Log_{0}.txt", DateTime.Now.ToString("yyyyMMdd")); | ||
// content = DateTime.Now.ToString("HH:mm:ss.ffffff") + " , " + content; | ||
// WriteLogFile(logPath, content, logName); | ||
//} | ||
|
||
/// <summary> | ||
/// 将即时日志保存入日志文件(bin目录下创建Log文件夹,按天生成日志文件) | ||
/// </summary> | ||
public static void WriteBinLog(string content, string forder = "Log", string fileName = "", bool autoTime = true, bool autoTimeFileName = true) | ||
{ | ||
try | ||
{ | ||
//string assemblyDirPath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); | ||
//string assemblyDirPath = HttpRuntime.AppDomainAppPath.ToString(); | ||
string logPath = assemblyDirPath; | ||
string logName = string.Format("{0}.txt", fileName); | ||
|
||
if (!string.IsNullOrEmpty(forder)) | ||
logPath = Path.Combine(assemblyDirPath, forder); | ||
|
||
if (string.IsNullOrEmpty(fileName)) | ||
fileName = forder; | ||
if (string.IsNullOrEmpty(fileName)) | ||
autoTimeFileName = true; | ||
if (autoTimeFileName) | ||
logName = string.Format("{0}_{1}.txt", fileName, DateTime.Now.ToString("yyyyMMdd")); | ||
|
||
if (autoTime) | ||
content = string.Format("{0},{1}", DateTime.Now.ToString("HH:mm:ss.ffffff"), content); | ||
|
||
WriteLogFile(logPath, content, logName); | ||
} | ||
catch (Exception ex) | ||
{ | ||
Console.WriteLine(ex.Message); | ||
//故意吞噬异常 | ||
} | ||
} | ||
|
||
private static object objLock = ""; | ||
/// <summary> | ||
/// 将即时日志保存入日志文件 | ||
/// </summary> | ||
public static void WriteLogFile(string directoryPath, string content, string fileName) | ||
{ | ||
//写入新的文件 | ||
string filePath = ""; | ||
if (directoryPath.Trim().Trim('/').Trim('\\') == "") | ||
{ | ||
filePath = fileName; | ||
} | ||
else | ||
{ | ||
if (!Directory.Exists(directoryPath)) | ||
CreateFolder(directoryPath); | ||
filePath = directoryPath + "\\" + fileName; | ||
} | ||
lock (objLock) | ||
{ | ||
using (FileStream fs = new FileStream(filePath, FileMode.Append, FileAccess.Write)) | ||
using (StreamWriter sw = new StreamWriter(fs)) | ||
{ | ||
sw.WriteLine(content); | ||
//sw.Flush(); | ||
sw.Close(); | ||
fs.Close(); | ||
} | ||
} | ||
} | ||
|
||
#region 控制台输出日志 | ||
static object cwLock = new object(); | ||
public static void WriteLine(string msg, object arg0, object arg1, object arg2) | ||
{ | ||
string tips = string.Format(msg, arg0, arg1, arg2); | ||
WriteLine(tips); | ||
} | ||
public static void WriteLine(string msg, object arg0, object arg1) | ||
{ | ||
string tips = string.Format(msg, arg0, arg1); | ||
WriteLine(tips); | ||
} | ||
public static void WriteLine(string msg, object arg0) | ||
{ | ||
string tips = string.Format(msg, arg0); | ||
WriteLine(tips); | ||
} | ||
public static void WriteLine(string msg, ConsoleColor color = ConsoleColor.Gray, bool prefixTime = true) | ||
{ | ||
try | ||
{ | ||
//关闭控制台显示时候,Console已释放,可能会调用到 Console.WriteLine,所以要吞噬异常 | ||
//if (color != ConsoleColor.Gray) | ||
//{ | ||
lock (cwLock) | ||
{ | ||
Console.ForegroundColor = color; | ||
Console.WriteLine("{0}, {1}", DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss.fffffff"), msg); | ||
Console.ResetColor(); | ||
} | ||
//} | ||
//else | ||
//{ | ||
// Console.WriteLine("{0}, {1}", DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss.fffffff"), msg); | ||
//} | ||
} | ||
catch (Exception) | ||
{ | ||
} | ||
} | ||
#endregion | ||
|
||
} | ||
} |
Oops, something went wrong.