Skip to content

Commit 9844223

Browse files
committed
Broke solution up into 3 parts: A common core library, a windows GUI and a automated console version that takes only a .config file as input.
1 parent 49f9221 commit 9844223

26 files changed

Lines changed: 1670 additions & 1228 deletions

.gitignore

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,12 @@
55
/.vs
66
/obj
77
/bin
8+
9+
/WELSConsole/bin
10+
/WELSConsole/obj
11+
12+
/WELSCore/bin
13+
/WELSCore/obj
14+
15+
/WELSearchGUI/bin
16+
/WELSearchGUI/obj

Form1.cs

Lines changed: 0 additions & 164 deletions
This file was deleted.

Program.cs

Lines changed: 0 additions & 22 deletions
This file was deleted.

WELSConsole/App.config

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?xml version="1.0" encoding="utf-8" ?>
2+
<configuration>
3+
<startup>
4+
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.8" />
5+
</startup>
6+
<appSettings>
7+
8+
<add key="Path.Input" value="C:\Temp\wEventLogSearch\InputEventFiles.evtx"/>
9+
<add key="Path.Output" value="C:\Temp\wEventLogSearch\EventLogSearch.csv"/>
10+
11+
<add key="Search.EventIDs" value="4689 or EventID=4688"/>
12+
<add key="Search.Filter" value=""/>
13+
<add key="Search.ValueLocations" value=""/>
14+
<add key="Search.TimeDifference" value="-1"/>
15+
16+
<add key="Bool.InputIsSingleFile" value="True"/>
17+
<add key="Bool.IncludeLogSource" value="True"/>
18+
<add key="Bool.GroupIntoOneColumn" value="False"/>
19+
20+
</appSettings>
21+
</configuration>

WELSConsole/Configuration.cs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
7+
namespace WELSConsole
8+
{
9+
public static class Configuration
10+
{
11+
public static string Path_Input = ConfigurationReader.GetConfigurationValue<string>("Path.Input") ?? "";
12+
public static string Path_Output = ConfigurationReader.GetConfigurationValue<string>("Path.Output") ?? "";
13+
14+
public static string Search_EventIDs = ConfigurationReader.GetConfigurationValue<string>("Search.EventIDs") ?? "";
15+
public static string Search_Filter = ConfigurationReader.GetConfigurationValue<string>("Search.Filter") ?? "";
16+
public static string Search_ValueLocations = ConfigurationReader.GetConfigurationValue<string>("Search.ValueLocations") ?? "";
17+
public static long Search_TimeDifference = ConfigurationReader.GetConfigurationValue<long>("Search.TimeDifference");
18+
19+
public static bool Bool_InputIsSingleFile = ConfigurationReader.GetConfigurationValue<bool>("Bool.InputIsSingleFile");
20+
public static bool Bool_IncludeLogSource = ConfigurationReader.GetConfigurationValue<bool>("Bool.IncludeLogSource");
21+
public static bool Bool_GroupIntoOneColumn = ConfigurationReader.GetConfigurationValue<bool>("Bool.GroupIntoOneColumn");
22+
}
23+
}

WELSConsole/ConfigurationReader.cs

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Configuration;
6+
7+
namespace WELSConsole
8+
{
9+
public static class ConfigurationReader
10+
{
11+
public static T GetConfigurationValue<T>(string SettingName)
12+
{
13+
if (ConfigurationExists(SettingName))
14+
{
15+
T result = (T)Convert.ChangeType(ConfigurationManager.AppSettings[SettingName], typeof(T));
16+
if (result != null)
17+
{
18+
return result;
19+
}
20+
}
21+
return default(T);
22+
}
23+
24+
public static bool ConfigurationExists(string SettingName)
25+
{
26+
if (
27+
!string.IsNullOrWhiteSpace(SettingName)
28+
&& ConfigurationManager.AppSettings.HasKeys()
29+
&& !string.IsNullOrWhiteSpace(ConfigurationManager.AppSettings[SettingName])
30+
)
31+
{
32+
return true;
33+
}
34+
else
35+
{
36+
return false;
37+
}
38+
}
39+
}
40+
}

WELSConsole/Program.cs

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
using WELSCore;
7+
8+
namespace WELSConsole
9+
{
10+
internal class Program
11+
{
12+
static void Main(string[] args)
13+
{
14+
AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;
15+
16+
LogInformation($"{AppDomain.CurrentDomain.FriendlyName} executed on: {DateTime.Now.ToLongDateString()} at {DateTime.Now.ToLongTimeString()}.");
17+
SearchParameters parameters = GetSearchParameters();
18+
LogInformation($"Configuration acquired from {AppDomain.CurrentDomain.FriendlyName}.config. Starting Search...");
19+
SearchCore.Search(parameters);
20+
LogInformation($"Search completed on {DateTime.Now.ToLongDateString()} at {DateTime.Now.ToLongTimeString()}. Exiting...");
21+
}
22+
23+
private static SearchParameters GetSearchParameters()
24+
{
25+
SearchParameters result = new SearchParameters()
26+
{
27+
LogInformationFunction = LogInformation,
28+
LogErrorFunction = LogError,
29+
LogExceptionFunction = LogException,
30+
31+
InputPath = Configuration.Path_Input,
32+
OutputPath = Configuration.Path_Output,
33+
34+
EventIDs = Configuration.Search_EventIDs,
35+
Filter = Configuration.Search_Filter,
36+
ValueLocations = Configuration.Search_ValueLocations,
37+
TimeDifference = Configuration.Search_TimeDifference,
38+
39+
InputIsSingleFile = Configuration.Bool_InputIsSingleFile,
40+
IncludeLogSource = Configuration.Bool_IncludeLogSource,
41+
GroupIntoOneColumn = Configuration.Bool_GroupIntoOneColumn
42+
};
43+
44+
return result;
45+
}
46+
47+
private static void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
48+
{
49+
LogException($"Global exception handler caught an exception! Is terminating: {e.IsTerminating}.", (Exception)e.ExceptionObject);
50+
}
51+
52+
private static void LogInformation(string message)
53+
{
54+
Console.WriteLine(message);
55+
}
56+
57+
private static void LogError(string message)
58+
{
59+
Console.ForegroundColor = ConsoleColor.Red;
60+
Console.Error.WriteLine(message);
61+
Console.ResetColor();
62+
}
63+
64+
private static void LogException(string message, Exception ex)
65+
{
66+
LogError(message);
67+
LogError(ex.ToString());
68+
}
69+
}
70+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
using System.Reflection;
2+
using System.Runtime.CompilerServices;
3+
using System.Runtime.InteropServices;
4+
5+
// General Information about an assembly is controlled through the following
6+
// set of attributes. Change these attribute values to modify the information
7+
// associated with an assembly.
8+
[assembly: AssemblyTitle("WindowsEventLogSearchConsole")]
9+
[assembly: AssemblyDescription("https://github.com/RandomRhythm/wEventLogSearch")]
10+
[assembly: AssemblyConfiguration("")]
11+
[assembly: AssemblyCompany("")]
12+
[assembly: AssemblyProduct("WindowsEventLogSearchConsole")]
13+
[assembly: AssemblyCopyright("Copyright © Ryan B & Adam White 2023")]
14+
[assembly: AssemblyCulture("")]
15+
16+
// Setting ComVisible to false makes the types in this assembly not visible
17+
// to COM components. If you need to access a type in this assembly from
18+
// COM, set the ComVisible attribute to true on that type.
19+
[assembly: ComVisible(false)]
20+
21+
// The following GUID is for the ID of the typelib if this project is exposed to COM
22+
[assembly: Guid("34e0bbce-cc08-40df-a0db-544f54c5130c")]
23+
24+
// Version information for an assembly consists of the following four values:
25+
//
26+
// Major Version
27+
// Minor Version
28+
// Build Number
29+
// Revision
30+
//
31+
// You can specify all the values or you can default the Build and Revision Numbers
32+
// by using the '*' as shown below:
33+
// [assembly: AssemblyVersion("1.0.*")]
34+
[assembly: AssemblyVersion("1.0.0.0")]
35+
[assembly: AssemblyFileVersion("1.0.0.0")]

0 commit comments

Comments
 (0)