Änderung
- Das Schreiben eines Headers wurde entfernt - Schreiben einer Logzeile ohne Zeit neu dazu - Ersetz das Schreiben eines Headers - Funktioniert jederzeit - Millisekunden werden immer auf drei Stellen formatiert - Message-Text korrigiert
This commit is contained in:
parent
adbb61a3fd
commit
c6da990e8b
Binary file not shown.
2
LogWriter/AppResources.Designer.cs
generated
2
LogWriter/AppResources.Designer.cs
generated
@ -61,7 +61,7 @@ namespace Eugen.ESystem.IO {
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sucht eine lokalisierte Zeichenfolge, die The directory specifyed in Path was not found ähnelt.
|
||||
/// Sucht eine lokalisierte Zeichenfolge, die The directory specifyed in Path was not found. ähnelt.
|
||||
/// </summary>
|
||||
internal static string msg001 {
|
||||
get {
|
||||
|
||||
@ -118,7 +118,7 @@
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<data name="msg001" xml:space="preserve">
|
||||
<value>Das in Pfad angegebene Verzeichnis wurde nicht gefunden</value>
|
||||
<value>Das in Pfad angegebene Verzeichnis wurde nicht gefunden.</value>
|
||||
</data>
|
||||
<data name="msg002" xml:space="preserve">
|
||||
<value>FileFormat hat das falsche Format.</value>
|
||||
|
||||
@ -118,7 +118,7 @@
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<data name="msg001" xml:space="preserve">
|
||||
<value>The directory specifyed in Path was not found</value>
|
||||
<value>The directory specifyed in Path was not found.</value>
|
||||
</data>
|
||||
<data name="msg002" xml:space="preserve">
|
||||
<value>FileFormat has the wrong format.</value>
|
||||
|
||||
@ -129,6 +129,14 @@ namespace Eugen.ESystem.IO
|
||||
protected string ProgramCopyright { private set; get; }
|
||||
#endregion
|
||||
|
||||
#region enum
|
||||
public enum Time
|
||||
{
|
||||
Write,
|
||||
NoWrite
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region delegates
|
||||
/// <summary>
|
||||
/// Provides a method, wich handles events from written messages
|
||||
@ -271,23 +279,6 @@ namespace Eugen.ESystem.IO
|
||||
this.filename.Replace(".log", "");
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Constructor (Filename = self defined, with fileheader)
|
||||
/// </summary>
|
||||
/// <param name="path"></param>
|
||||
/// <param name="filename"></param>
|
||||
/// <param name="fileheader"></param>
|
||||
public LogWriter(string path, string filename, string logheader)
|
||||
{
|
||||
this.path = path;
|
||||
this.filename = filename;
|
||||
if (this.filename.EndsWith(".log"))
|
||||
{
|
||||
this.filename.Replace(".log", "");
|
||||
}
|
||||
this.logheader = logheader;
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region public members
|
||||
@ -297,6 +288,17 @@ namespace Eugen.ESystem.IO
|
||||
/// <param name="message">Specifyes the message to be written</param>
|
||||
/// <returns>Wheather the writing progress was successful</returns>
|
||||
public bool WriteMessage(string message)
|
||||
{
|
||||
return WriteMessage(message, Time.Write);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Writes a message
|
||||
/// </summary>
|
||||
/// <param name="message">Specifyes the message to be written</param>
|
||||
/// <param name="writeTime">Indicates whether the time is written or not</param>
|
||||
/// <returns>Wheather the writing progress was successful</returns>
|
||||
public bool WriteMessage(string message, Time writeTime)
|
||||
{
|
||||
// if directory not exists, cancel
|
||||
if (!Directory.Exists(this.path))
|
||||
@ -305,6 +307,8 @@ namespace Eugen.ESystem.IO
|
||||
// holds the actual date and time
|
||||
DateTime time = DateTime.Now;
|
||||
int ms = time.Millisecond;
|
||||
string fmt = "000";
|
||||
string ms3 = ms.ToString(fmt);
|
||||
|
||||
// creates the file name
|
||||
string fileName;
|
||||
@ -369,7 +373,15 @@ namespace Eugen.ESystem.IO
|
||||
try
|
||||
{
|
||||
// creates the line
|
||||
line = String.Format(this.messageFormat, new object[] { time, ms, message });
|
||||
if (writeTime == Time.Write)
|
||||
{
|
||||
line = String.Format(this.messageFormat, new object[] { time, ms3, message });
|
||||
}
|
||||
else
|
||||
{
|
||||
line = String.Empty;
|
||||
line = message;
|
||||
}
|
||||
}
|
||||
catch (FormatException)
|
||||
{
|
||||
@ -384,26 +396,6 @@ namespace Eugen.ESystem.IO
|
||||
{
|
||||
StreamWriter writer;
|
||||
|
||||
// if a log header is to be written
|
||||
if (!String.IsNullOrEmpty(logheader) && IsFileEmpty(fileName))
|
||||
{
|
||||
// write log header
|
||||
// open file
|
||||
if (!File.Exists(fileName))
|
||||
{
|
||||
writer = new StreamWriter(fileName);
|
||||
OnFileCreated(EventArgs.Empty);
|
||||
}
|
||||
else
|
||||
writer = new StreamWriter(fileName);
|
||||
|
||||
// write message line
|
||||
writer.WriteLine(this.logheader);
|
||||
|
||||
// close file
|
||||
writer.Close();
|
||||
}
|
||||
|
||||
// open file
|
||||
if (!File.Exists(fileName))
|
||||
{
|
||||
@ -411,7 +403,9 @@ namespace Eugen.ESystem.IO
|
||||
OnFileCreated(EventArgs.Empty);
|
||||
}
|
||||
else
|
||||
{
|
||||
writer = new StreamWriter(fileName, true);
|
||||
}
|
||||
|
||||
// write message line
|
||||
writer.WriteLine(line);
|
||||
@ -530,6 +524,7 @@ namespace Eugen.ESystem.IO
|
||||
/// Constructor
|
||||
/// </summary>
|
||||
/// <param name="time">Specifyes the message post time</param>
|
||||
/// <param name="millisecond">Specifyes the message post milliseconds</param>
|
||||
/// <param name="message">Specifyes the message</param>
|
||||
public LogWriterEventArgs(DateTime time, int millisecond, string message)
|
||||
: base()
|
||||
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -1,13 +1,14 @@
|
||||
H:\Programmieren\Git-WorkRepository\VisualStudio\_DLL\LogWriter.git\LogWriter\obj\Debug\LogWriter.csproj.CoreCompileInputs.cache
|
||||
H:\Programmieren\Git-WorkRepository\VisualStudio\_DLL\LogWriter.git\LogWriter\bin\Debug\helogwri.dll
|
||||
H:\Programmieren\Git-WorkRepository\VisualStudio\_DLL\LogWriter.git\LogWriter\bin\Debug\helogwri.pdb
|
||||
H:\Programmieren\Git-WorkRepository\VisualStudio\_DLL\LogWriter.git\LogWriter\obj\Debug\helogwri.dll
|
||||
H:\Programmieren\Git-WorkRepository\VisualStudio\_DLL\LogWriter.git\LogWriter\obj\Debug\helogwri.pdb
|
||||
H:\Programmieren\Git-WorkRepository\VisualStudio\_DLL\LogWriter.git\LogWriter\bin\Debug\de\helogwri.resources.dll
|
||||
H:\Programmieren\Git-WorkRepository\VisualStudio\_DLL\LogWriter.git\LogWriter\bin\Debug\en\helogwri.resources.dll
|
||||
H:\Programmieren\Git-WorkRepository\VisualStudio\_DLL\LogWriter.git\LogWriter\obj\Debug\LogWriter.csproj.AssemblyReference.cache
|
||||
H:\Programmieren\Git-WorkRepository\VisualStudio\_DLL\LogWriter.git\LogWriter\obj\Debug\LogWriter.AppResources.resources
|
||||
H:\Programmieren\Git-WorkRepository\VisualStudio\_DLL\LogWriter.git\LogWriter\obj\Debug\LogWriter.AppResources.de.resources
|
||||
H:\Programmieren\Git-WorkRepository\VisualStudio\_DLL\LogWriter.git\LogWriter\obj\Debug\LogWriter.AppResources.en.resources
|
||||
H:\Programmieren\Git-WorkRepository\VisualStudio\_DLL\LogWriter.git\LogWriter\obj\Debug\LogWriter.csproj.GenerateResource.cache
|
||||
H:\Programmieren\Git-WorkRepository\VisualStudio\_DLL\LogWriter.git\LogWriter\bin\Debug\de\helogwri.resources.dll
|
||||
H:\Programmieren\Git-WorkRepository\VisualStudio\_DLL\LogWriter.git\LogWriter\bin\Debug\en\helogwri.resources.dll
|
||||
H:\Programmieren\Git-WorkRepository\VisualStudio\_DLL\LogWriter.git\LogWriter\obj\Debug\LogWriter.csproj.CoreCompileInputs.cache
|
||||
H:\Programmieren\Git-WorkRepository\VisualStudio\_DLL\LogWriter.git\LogWriter\obj\Debug\de\helogwri.resources.dll
|
||||
H:\Programmieren\Git-WorkRepository\VisualStudio\_DLL\LogWriter.git\LogWriter\obj\Debug\en\helogwri.resources.dll
|
||||
H:\Programmieren\Git-WorkRepository\VisualStudio\_DLL\LogWriter.git\LogWriter\obj\Debug\helogwri.dll
|
||||
H:\Programmieren\Git-WorkRepository\VisualStudio\_DLL\LogWriter.git\LogWriter\obj\Debug\helogwri.pdb
|
||||
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -141,8 +141,9 @@ namespace Test_LogWriter
|
||||
labelResult.Text = String.Concat(labelResult.Text, "\nDie Log-Datei C:\\TMP\\my_logfile2.log wurde geschrieben");
|
||||
|
||||
//Variante 3 - Logdateiname wird angegeben und Header wird geschrieben
|
||||
string header = "--------------------\nDas ist der Header\n--------------------";
|
||||
var logWriter3 = new LogWriter(@"C:\TMP\", "my_logfile3", header);
|
||||
string header = "--------------------\n Das ist der Header\n--------------------";
|
||||
var logWriter3 = new LogWriter(@"C:\TMP\", "my_logfile3");
|
||||
logWriter3.WriteMessage(header, LogWriter.Time.NoWrite);
|
||||
logWriter3.WriteMessage("Das ist Test 3");
|
||||
labelResult.Text = String.Concat(labelResult.Text, "\nDie Log-Datei C:\\TMP\\my_logfile3.log wurde geschrieben");
|
||||
}
|
||||
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -1,17 +1,17 @@
|
||||
H:\Programmieren\Git-WorkRepository\VisualStudio\_DLL\LogWriter.git\Test_LogWriter\bin\Debug\Test_LogWriter.exe.config
|
||||
H:\Programmieren\Git-WorkRepository\VisualStudio\_DLL\LogWriter.git\Test_LogWriter\bin\Debug\Test_LogWriter.exe
|
||||
H:\Programmieren\Git-WorkRepository\VisualStudio\_DLL\LogWriter.git\Test_LogWriter\bin\Debug\Test_LogWriter.pdb
|
||||
H:\Programmieren\Git-WorkRepository\VisualStudio\_DLL\LogWriter.git\Test_LogWriter\bin\Debug\helogwri.dll
|
||||
H:\Programmieren\Git-WorkRepository\VisualStudio\_DLL\LogWriter.git\Test_LogWriter\bin\Debug\heshowtf.dll
|
||||
H:\Programmieren\Git-WorkRepository\VisualStudio\_DLL\LogWriter.git\Test_LogWriter\bin\Debug\helogwri.pdb
|
||||
H:\Programmieren\Git-WorkRepository\VisualStudio\_DLL\LogWriter.git\Test_LogWriter\bin\Debug\heshowtf.pdb
|
||||
H:\Programmieren\Git-WorkRepository\VisualStudio\_DLL\LogWriter.git\Test_LogWriter\bin\Debug\de\helogwri.resources.dll
|
||||
H:\Programmieren\Git-WorkRepository\VisualStudio\_DLL\LogWriter.git\Test_LogWriter\bin\Debug\en\helogwri.resources.dll
|
||||
H:\Programmieren\Git-WorkRepository\VisualStudio\_DLL\LogWriter.git\Test_LogWriter\obj\Debug\Test_LogWriter.csproj.AssemblyReference.cache
|
||||
H:\Programmieren\Git-WorkRepository\VisualStudio\_DLL\LogWriter.git\Test_LogWriter\obj\Debug\Test_LogWriter.Form1.resources
|
||||
H:\Programmieren\Git-WorkRepository\VisualStudio\_DLL\LogWriter.git\Test_LogWriter\obj\Debug\Test_LogWriter.Properties.Resources.resources
|
||||
H:\Programmieren\Git-WorkRepository\VisualStudio\_DLL\LogWriter.git\Test_LogWriter\obj\Debug\Test_LogWriter.csproj.GenerateResource.cache
|
||||
H:\Programmieren\Git-WorkRepository\VisualStudio\_DLL\LogWriter.git\Test_LogWriter\obj\Debug\Test_LogWriter.csproj.CoreCompileInputs.cache
|
||||
H:\Programmieren\Git-WorkRepository\VisualStudio\_DLL\LogWriter.git\Test_LogWriter\bin\Debug\Test_LogWriter.exe.config
|
||||
H:\Programmieren\Git-WorkRepository\VisualStudio\_DLL\LogWriter.git\Test_LogWriter\bin\Debug\Test_LogWriter.exe
|
||||
H:\Programmieren\Git-WorkRepository\VisualStudio\_DLL\LogWriter.git\Test_LogWriter\bin\Debug\Test_LogWriter.pdb
|
||||
H:\Programmieren\Git-WorkRepository\VisualStudio\_DLL\LogWriter.git\Test_LogWriter\bin\Debug\helogwri.pdb
|
||||
H:\Programmieren\Git-WorkRepository\VisualStudio\_DLL\LogWriter.git\Test_LogWriter\obj\Debug\Test_LogWriter.csproj.CopyComplete
|
||||
H:\Programmieren\Git-WorkRepository\VisualStudio\_DLL\LogWriter.git\Test_LogWriter\obj\Debug\Test_LogWriter.exe
|
||||
H:\Programmieren\Git-WorkRepository\VisualStudio\_DLL\LogWriter.git\Test_LogWriter\obj\Debug\Test_LogWriter.pdb
|
||||
H:\Programmieren\Git-WorkRepository\VisualStudio\_DLL\LogWriter.git\Test_LogWriter\bin\Debug\helogwri.dll
|
||||
H:\Programmieren\Git-WorkRepository\VisualStudio\_DLL\LogWriter.git\Test_LogWriter\bin\Debug\de\helogwri.resources.dll
|
||||
H:\Programmieren\Git-WorkRepository\VisualStudio\_DLL\LogWriter.git\Test_LogWriter\bin\Debug\en\helogwri.resources.dll
|
||||
H:\Programmieren\Git-WorkRepository\VisualStudio\_DLL\LogWriter.git\Test_LogWriter\bin\Debug\heshowtf.dll
|
||||
H:\Programmieren\Git-WorkRepository\VisualStudio\_DLL\LogWriter.git\Test_LogWriter\bin\Debug\heshowtf.pdb
|
||||
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading…
Reference in New Issue
Block a user