Skip to content

Commit 71a96fe

Browse files
committed
Issue #1 - Added option to specify the timestamp format to parse
1 parent 8e889a9 commit 71a96fe

File tree

12 files changed

+1477
-638
lines changed

12 files changed

+1477
-638
lines changed

src/Logbert/Dialogs/FrmColumnizer.Designer.cs

Lines changed: 318 additions & 305 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Logbert/Dialogs/FrmColumnizer.cs

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -445,6 +445,20 @@ private void TsbEditLogLevelsClick(object sender, System.EventArgs e)
445445
}
446446
}
447447

448+
/// <summary>
449+
/// Handles the Click event of the edit timestamp format <see cref="ToolStripButton"/>.
450+
/// </summary>
451+
private void TsbEditDateTimeFormatClick(object sender, System.EventArgs e)
452+
{
453+
using (FrmEditTimeStampFormat logLevelDlg = new FrmEditTimeStampFormat(mColumnizer.DateTimeFormat))
454+
{
455+
if (logLevelDlg.ShowDialog(this) == DialogResult.OK)
456+
{
457+
mColumnizer.DateTimeFormat = logLevelDlg.DateTimeFormat;
458+
}
459+
}
460+
}
461+
448462
#endregion
449463

450464
#region Constructor
@@ -471,6 +485,7 @@ public FrmColumnizer(Columnizer columnizer)
471485
tsColumns.Renderer = new CustomToolStripSystemRenderer();
472486
}
473487

474-
#endregion
475-
}
488+
#endregion
489+
490+
}
476491
}

src/Logbert/Dialogs/FrmEditTimeStampFormat.Designer.cs

Lines changed: 529 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
#region Copyright © 2017 Couchcoding
2+
3+
// File: FrmEditTimeStampFormat.cs
4+
// Package: Logbert
5+
// Project: Logbert
6+
//
7+
// The MIT License (MIT)
8+
//
9+
// Copyright (c) 2017 Couchcoding
10+
//
11+
// Permission is hereby granted, free of charge, to any person obtaining a copy
12+
// of this software and associated documentation files (the "Software"), to deal
13+
// in the Software without restriction, including without limitation the rights
14+
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
15+
// copies of the Software, and to permit persons to whom the Software is
16+
// furnished to do so, subject to the following conditions:
17+
//
18+
// The above copyright notice and this permission notice shall be included in
19+
// all copies or substantial portions of the Software.
20+
//
21+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
22+
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
23+
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
24+
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
25+
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
26+
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
27+
// THE SOFTWARE.
28+
29+
#endregion
30+
31+
using System.Drawing;
32+
using System.Windows.Forms;
33+
34+
using Com.Couchcoding.GuiLibrary.Dialogs;
35+
using Com.Couchcoding.Logbert.Receiver.CustomReceiver;
36+
37+
namespace Com.Couchcoding.Logbert.Dialogs
38+
{
39+
/// <summary>
40+
/// Implements a dialog to edit the timestamp format to parse.
41+
/// </summary>
42+
public partial class FrmEditTimeStampFormat : DialogForm
43+
{
44+
#region Public Properties
45+
46+
/// <summary>
47+
/// Gets the specified timestamp format to parse.
48+
/// </summary>
49+
public string DateTimeFormat => txtTimestampFormat.Text ?? Columnizer.DefaultDateTimeFormat;
50+
51+
#endregion
52+
53+
#region Private Methods
54+
55+
/// <summary>
56+
/// Handles the ButtonClick event of the timestamp help <see cref="Button"/>.
57+
/// </summary>
58+
private void TxtTimestampFormatButtonClick(object sender, System.EventArgs e)
59+
{
60+
Control btnTimestamp = sender as Control;
61+
62+
if (btnTimestamp != null)
63+
{
64+
mnuTimestamp.Show(
65+
btnTimestamp
66+
, new Point(btnTimestamp.Width, btnTimestamp.Top));
67+
}
68+
}
69+
70+
/// <summary>
71+
/// Handles the Click event of a timestamp help <see cref="MenuItem"/>.
72+
/// </summary>
73+
private void MnuTimestampClick(object sender, System.EventArgs e)
74+
{
75+
ToolStripMenuItem mnuCtrl = sender as ToolStripMenuItem;
76+
77+
if (mnuCtrl?.Tag != null)
78+
{
79+
txtTimestampFormat.SelectedText = mnuCtrl.Tag.ToString();
80+
}
81+
}
82+
83+
#endregion
84+
85+
#region Constructor
86+
87+
/// <summary>
88+
/// Initializes a new instance of the <see cref="FrmEditTimeStampFormat"/> dialog.
89+
/// </summary>
90+
public FrmEditTimeStampFormat()
91+
{
92+
InitializeComponent();
93+
}
94+
95+
/// <summary>
96+
/// Initializes a new instance of the <see cref="FrmEditTimeStampFormat"/> dialog with the specified parameters.
97+
/// </summary>
98+
/// <param name="format">The initial timestamp format to display.</param>
99+
public FrmEditTimeStampFormat(string format)
100+
{
101+
InitializeComponent();
102+
103+
txtTimestampFormat.Text = format ?? Columnizer.DefaultDateTimeFormat;
104+
}
105+
106+
#endregion
107+
}
108+
}
Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<root>
3+
<!--
4+
Microsoft ResX Schema
5+
6+
Version 2.0
7+
8+
The primary goals of this format is to allow a simple XML format
9+
that is mostly human readable. The generation and parsing of the
10+
various data types are done through the TypeConverter classes
11+
associated with the data types.
12+
13+
Example:
14+
15+
... ado.net/XML headers & schema ...
16+
<resheader name="resmimetype">text/microsoft-resx</resheader>
17+
<resheader name="version">2.0</resheader>
18+
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
19+
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
20+
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
21+
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
22+
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
23+
<value>[base64 mime encoded serialized .NET Framework object]</value>
24+
</data>
25+
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
26+
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
27+
<comment>This is a comment</comment>
28+
</data>
29+
30+
There are any number of "resheader" rows that contain simple
31+
name/value pairs.
32+
33+
Each data row contains a name, and value. The row also contains a
34+
type or mimetype. Type corresponds to a .NET class that support
35+
text/value conversion through the TypeConverter architecture.
36+
Classes that don't support this are serialized and stored with the
37+
mimetype set.
38+
39+
The mimetype is used for serialized objects, and tells the
40+
ResXResourceReader how to depersist the object. This is currently not
41+
extensible. For a given mimetype the value must be set accordingly:
42+
43+
Note - application/x-microsoft.net.object.binary.base64 is the format
44+
that the ResXResourceWriter will generate, however the reader can
45+
read any of the formats listed below.
46+
47+
mimetype: application/x-microsoft.net.object.binary.base64
48+
value : The object must be serialized with
49+
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
50+
: and then encoded with base64 encoding.
51+
52+
mimetype: application/x-microsoft.net.object.soap.base64
53+
value : The object must be serialized with
54+
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
55+
: and then encoded with base64 encoding.
56+
57+
mimetype: application/x-microsoft.net.object.bytearray.base64
58+
value : The object must be serialized into a byte array
59+
: using a System.ComponentModel.TypeConverter
60+
: and then encoded with base64 encoding.
61+
-->
62+
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
63+
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
64+
<xsd:element name="root" msdata:IsDataSet="true">
65+
<xsd:complexType>
66+
<xsd:choice maxOccurs="unbounded">
67+
<xsd:element name="metadata">
68+
<xsd:complexType>
69+
<xsd:sequence>
70+
<xsd:element name="value" type="xsd:string" minOccurs="0" />
71+
</xsd:sequence>
72+
<xsd:attribute name="name" use="required" type="xsd:string" />
73+
<xsd:attribute name="type" type="xsd:string" />
74+
<xsd:attribute name="mimetype" type="xsd:string" />
75+
<xsd:attribute ref="xml:space" />
76+
</xsd:complexType>
77+
</xsd:element>
78+
<xsd:element name="assembly">
79+
<xsd:complexType>
80+
<xsd:attribute name="alias" type="xsd:string" />
81+
<xsd:attribute name="name" type="xsd:string" />
82+
</xsd:complexType>
83+
</xsd:element>
84+
<xsd:element name="data">
85+
<xsd:complexType>
86+
<xsd:sequence>
87+
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
88+
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
89+
</xsd:sequence>
90+
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
91+
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
92+
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
93+
<xsd:attribute ref="xml:space" />
94+
</xsd:complexType>
95+
</xsd:element>
96+
<xsd:element name="resheader">
97+
<xsd:complexType>
98+
<xsd:sequence>
99+
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
100+
</xsd:sequence>
101+
<xsd:attribute name="name" type="xsd:string" use="required" />
102+
</xsd:complexType>
103+
</xsd:element>
104+
</xsd:choice>
105+
</xsd:complexType>
106+
</xsd:element>
107+
</xsd:schema>
108+
<resheader name="resmimetype">
109+
<value>text/microsoft-resx</value>
110+
</resheader>
111+
<resheader name="version">
112+
<value>2.0</value>
113+
</resheader>
114+
<resheader name="reader">
115+
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
116+
</resheader>
117+
<resheader name="writer">
118+
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
119+
</resheader>
120+
<metadata name="mnuTimestamp.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
121+
<value>17, 17</value>
122+
</metadata>
123+
</root>

src/Logbert/Logbert.csproj

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,12 @@
166166
<Compile Include="Controls\OptionPanels\OptionPanelGeneral.Designer.cs">
167167
<DependentUpon>OptionPanelGeneral.cs</DependentUpon>
168168
</Compile>
169+
<Compile Include="Dialogs\FrmEditTimeStampFormat.cs">
170+
<SubType>Form</SubType>
171+
</Compile>
172+
<Compile Include="Dialogs\FrmEditTimeStampFormat.Designer.cs">
173+
<DependentUpon>FrmEditTimeStampFormat.cs</DependentUpon>
174+
</Compile>
169175
<Compile Include="Dialogs\Docking\FrmLogBookmarks.cs">
170176
<SubType>Form</SubType>
171177
</Compile>
@@ -429,6 +435,9 @@
429435
<EmbeddedResource Include="Controls\OptionPanels\OptionPanelGeneral.resx">
430436
<DependentUpon>OptionPanelGeneral.cs</DependentUpon>
431437
</EmbeddedResource>
438+
<EmbeddedResource Include="Dialogs\FrmEditTimeStampFormat.resx">
439+
<DependentUpon>FrmEditTimeStampFormat.cs</DependentUpon>
440+
</EmbeddedResource>
432441
<EmbeddedResource Include="Dialogs\Docking\FrmLogBookmarks.resx">
433442
<DependentUpon>FrmLogBookmarks.cs</DependentUpon>
434443
</EmbeddedResource>
@@ -539,6 +548,7 @@
539548
<BaseApplicationManifest Include="Properties\app.manifest" />
540549
</ItemGroup>
541550
<ItemGroup>
551+
<None Include="Resources\VSO_Time_16x.png" />
542552
<None Include="Resources\LogLevel_16x.png" />
543553
<None Include="Resources\FrmStatisticShowLegend.png" />
544554
<None Include="Resources\FrmLogStatistic.png" />

src/Logbert/Logging/LogMessageCustom.cs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,12 @@
3131
using System;
3232
using Com.Couchcoding.Logbert.Receiver.CustomReceiver;
3333
using System.Collections.Generic;
34+
using System.Globalization;
3435
using System.Text.RegularExpressions;
3536
using Com.Couchcoding.Logbert.Properties;
3637
using System.Text;
38+
using System.Windows.Forms;
39+
3740
using Com.Couchcoding.Logbert.Helper;
3841
using MoonSharp.Interpreter;
3942

@@ -137,7 +140,7 @@ private bool ParseData(string data)
137140
switch (mColumnizer.Columns[i].ColumnType)
138141
{
139142
case LogColumnType.Timestamp:
140-
if (!DateTime.TryParse(mParsedValue[i], out mTimestamp))
143+
if (!DateTime.TryParseExact(mParsedValue[i], mColumnizer.DateTimeFormat, CultureInfo.InvariantCulture, DateTimeStyles.None, out mTimestamp))
141144
{
142145
mTimestamp = DateTime.MinValue;
143146
}
@@ -152,9 +155,7 @@ private bool ParseData(string data)
152155
continue;
153156
}
154157

155-
Match mLgMtc = Regex.Match(mParsedValue[i], logLevelMap.Value);
156-
157-
if (mLgMtc.Success)
158+
if (Regex.Match(mParsedValue[i], logLevelMap.Value).Success)
158159
{
159160
mLevel = logLevelMap.Key;
160161
break;
@@ -230,7 +231,7 @@ public override string GetCsvLine()
230231
sBuilder.Remove(sBuilder.Length - 1, 1);
231232
}
232233

233-
return sBuilder.ToString() + Environment.NewLine;
234+
return sBuilder + Environment.NewLine;
234235
}
235236

236237
/// <summary>

src/Logbert/Properties/AssemblyInfo.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,6 @@
2929
// Build Number
3030
// Revision
3131
//
32-
[assembly: AssemblyVersion("1.3.2.1")]
33-
[assembly: AssemblyFileVersion("1.3.2.1")]
32+
[assembly: AssemblyVersion("1.3.3.0")]
33+
[assembly: AssemblyFileVersion("1.3.3.0")]
3434
[assembly: NeutralResourcesLanguageAttribute("")]

src/Logbert/Properties/Resources.Designer.cs

Lines changed: 11 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)