Skip to content

Commit 4e36496

Browse files
authored
Merge pull request #2 from AdamWhiteHat/Add-Filename-Tokenization
Add filename tokenization
2 parents c3c4619 + 1b0ba8a commit 4e36496

21 files changed

+296
-636
lines changed

WELSConsole/App.config

+6-7
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
1-
<?xml version="1.0" encoding="utf-8" ?>
1+
<?xml version="1.0" encoding="utf-8"?>
22
<configuration>
3-
<startup>
4-
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.8" />
5-
</startup>
63
<appSettings>
4+
<add key="LogFile.Output" value="Log.Output.txt"/>
5+
<add key="LogFile.Exception" value="Log.Exceptions.txt"/>
76

8-
<add key="Path.Input" value="C:\Temp\wEventLogSearch\InputEventFiles.evtx"/>
9-
<add key="Path.Output" value="C:\Temp\wEventLogSearch\EventLogSearch.csv"/>
7+
<add key="Path.Input" value="C:\Temp\wEventLogSearch\InputEventFiles-{MM}-{dd}-{yyyy}.evtx"/>
8+
<add key="Path.Output" value="C:\Temp\wEventLogSearch\Output-{MM}-{dd}-{yyyy}.csv"/>
109

1110
<add key="Search.EventIDs" value="4689 or EventID=4688"/>
1211
<add key="Search.Filter" value=""/>
@@ -18,4 +17,4 @@
1817
<add key="Bool.GroupIntoOneColumn" value="False"/>
1918

2019
</appSettings>
21-
</configuration>
20+
</configuration>

WELSConsole/Configuration.cs

+3
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ namespace WELSConsole
88
{
99
public static class Configuration
1010
{
11+
public static string LogFile_Output = ConfigurationReader.GetConfigurationValue<string>("LogFile.Output") ?? "Log.Output.txt";
12+
public static string LogFile_Exception = ConfigurationReader.GetConfigurationValue<string>("LogFile.Exception") ?? "Log.Exceptions.txt";
13+
1114
public static string Path_Input = ConfigurationReader.GetConfigurationValue<string>("Path.Input") ?? "";
1215
public static string Path_Output = ConfigurationReader.GetConfigurationValue<string>("Path.Output") ?? "";
1316

WELSConsole/Program.cs

+27-2
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,23 @@ namespace WELSConsole
99
{
1010
internal class Program
1111
{
12+
public static string LogFilenameException = "Log.Exceptions.txt";
13+
public static string LogFilenameOutput = "Log.Output.txt";
14+
1215
static void Main(string[] args)
1316
{
1417
AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;
1518

19+
if (!string.IsNullOrWhiteSpace(Configuration.LogFile_Output))
20+
{
21+
LogFilenameOutput = Configuration.LogFile_Output;
22+
}
23+
if (!string.IsNullOrWhiteSpace(Configuration.LogFile_Exception))
24+
{
25+
LogFilenameException = Configuration.LogFile_Exception;
26+
}
27+
28+
LogInformation("");
1629
LogInformation($"{AppDomain.CurrentDomain.FriendlyName} executed on: {DateTime.Now.ToLongDateString()} at {DateTime.Now.ToLongTimeString()}.");
1730
SearchParameters parameters = GetSearchParameters();
1831
LogInformation($"Configuration acquired from {AppDomain.CurrentDomain.FriendlyName}.config. Starting Search...");
@@ -28,8 +41,8 @@ private static SearchParameters GetSearchParameters()
2841
LogErrorFunction = LogError,
2942
LogExceptionFunction = LogException,
3043

31-
InputPath = Configuration.Path_Input,
32-
OutputPath = Configuration.Path_Output,
44+
InputPath = StringTokenReplace.ReplaceTokens(Configuration.Path_Input),
45+
OutputPath = StringTokenReplace.ReplaceTokens(Configuration.Path_Output),
3346

3447
EventIDs = Configuration.Search_EventIDs,
3548
Filter = Configuration.Search_Filter,
@@ -52,19 +65,31 @@ private static void CurrentDomain_UnhandledException(object sender, UnhandledExc
5265
private static void LogInformation(string message)
5366
{
5467
Console.WriteLine(message);
68+
LogOutput(message);
5569
}
5670

5771
private static void LogError(string message)
5872
{
5973
Console.ForegroundColor = ConsoleColor.Red;
6074
Console.Error.WriteLine(message);
6175
Console.ResetColor();
76+
LogOutput(message);
77+
}
78+
79+
private static void LogOutput(string message)
80+
{
81+
File.AppendAllText(LogFilenameOutput, message + Environment.NewLine);
6282
}
6383

6484
private static void LogException(string message, Exception ex)
6585
{
86+
string timeStamp = $"[{DateTime.Now.ToLongDateString()} at {DateTime.Now.ToLongTimeString()}]:";
6687
LogError(message);
6788
LogError(ex.ToString());
89+
90+
File.AppendAllText(LogFilenameException, $"{timeStamp} {message}" + Environment.NewLine);
91+
File.AppendAllText(LogFilenameException, $"{timeStamp} {ex}" + Environment.NewLine);
92+
File.AppendAllText(LogFilenameException, Environment.NewLine);
6893
}
6994
}
7095
}

WELSConsole/Properties/AssemblyInfo.cs

-35
This file was deleted.

WELSConsole/WELSConsole.csproj

+30-59
Original file line numberDiff line numberDiff line change
@@ -1,62 +1,33 @@
1-
<?xml version="1.0" encoding="utf-8"?>
2-
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3-
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
43
<PropertyGroup>
5-
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
6-
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
7-
<ProjectGuid>{34E0BBCE-CC08-40DF-A0DB-544F54C5130C}</ProjectGuid>
84
<OutputType>Exe</OutputType>
9-
<RootNamespace>WELSConsole</RootNamespace>
10-
<AssemblyName>WELSConsole</AssemblyName>
11-
<TargetFrameworkVersion>v4.8</TargetFrameworkVersion>
12-
<FileAlignment>512</FileAlignment>
13-
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
14-
<Deterministic>true</Deterministic>
5+
<TargetFramework>net7.0</TargetFramework>
6+
<ImplicitUsings>enable</ImplicitUsings>
7+
<Nullable>enable</Nullable>
158
</PropertyGroup>
16-
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
17-
<PlatformTarget>AnyCPU</PlatformTarget>
18-
<DebugSymbols>true</DebugSymbols>
19-
<DebugType>full</DebugType>
20-
<Optimize>false</Optimize>
21-
<OutputPath>bin\Debug\</OutputPath>
22-
<DefineConstants>DEBUG;TRACE</DefineConstants>
23-
<ErrorReport>prompt</ErrorReport>
24-
<WarningLevel>4</WarningLevel>
25-
</PropertyGroup>
26-
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
27-
<PlatformTarget>AnyCPU</PlatformTarget>
28-
<DebugType>pdbonly</DebugType>
29-
<Optimize>true</Optimize>
30-
<OutputPath>bin\Release\</OutputPath>
31-
<DefineConstants>TRACE</DefineConstants>
32-
<ErrorReport>prompt</ErrorReport>
33-
<WarningLevel>4</WarningLevel>
34-
</PropertyGroup>
35-
<ItemGroup>
36-
<Reference Include="System" />
37-
<Reference Include="System.Configuration" />
38-
<Reference Include="System.Core" />
39-
<Reference Include="System.Xml.Linq" />
40-
<Reference Include="System.Data.DataSetExtensions" />
41-
<Reference Include="Microsoft.CSharp" />
42-
<Reference Include="System.Data" />
43-
<Reference Include="System.Net.Http" />
44-
<Reference Include="System.Xml" />
45-
</ItemGroup>
46-
<ItemGroup>
47-
<Compile Include="Configuration.cs" />
48-
<Compile Include="ConfigurationReader.cs" />
49-
<Compile Include="Program.cs" />
50-
<Compile Include="Properties\AssemblyInfo.cs" />
51-
</ItemGroup>
52-
<ItemGroup>
53-
<None Include="App.config" />
54-
</ItemGroup>
55-
<ItemGroup>
56-
<ProjectReference Include="..\WELSCore\WELSCore.csproj">
57-
<Project>{bae13494-bf39-4533-b20a-5036d34eb131}</Project>
58-
<Name>WELSCore</Name>
59-
</ProjectReference>
60-
</ItemGroup>
61-
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
62-
</Project>
9+
10+
<PropertyGroup>
11+
<Title>WindowsEventLogSearchConsole</Title>
12+
<Product>WindowsEventLogSearchConsole</Product>
13+
<AssemblyName>WindowsEventLogSearchConsole</AssemblyName>
14+
15+
<Authors>Ryan B and Adam White</Authors>
16+
<Copyright>Copyright © Ryan B and Adam White 2023</Copyright>
17+
18+
<Version>$([System.DateTime]::Now.ToString("yyyy."$([System.DateTime]::Now.DayOfYear)".HHmm"))</Version>
19+
<AssemblyVersion>$([System.DateTime]::Now.ToString("yyyy."$([System.DateTime]::Now.DayOfYear)".HHmm"))</AssemblyVersion>
20+
<FileVersion>$([System.DateTime]::Now.ToString("yyyy."$([System.DateTime]::Now.DayOfYear)".HHmm"))</FileVersion>
21+
<StartupObject>WELSConsole.Program</StartupObject>
22+
<ProduceReferenceAssembly>False</ProduceReferenceAssembly>
23+
</PropertyGroup>
24+
25+
<ItemGroup>
26+
<PackageReference Include="System.Configuration.ConfigurationManager" Version="7.0.0" />
27+
</ItemGroup>
28+
29+
<ItemGroup>
30+
<ProjectReference Include="..\WELSCore\WELSCore.csproj" />
31+
</ItemGroup>
32+
33+
</Project>

WELSCore/EventLogHelper.cs

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using System.Text;
55
using System.Threading.Tasks;
66
using System.Diagnostics.Eventing.Reader;
7+
using System.Diagnostics;
78
using System.IO;
89
using System.Threading;
910
using System.Runtime.Serialization.Formatters.Binary;

WELSCore/Properties/AssemblyInfo.cs

-35
This file was deleted.

0 commit comments

Comments
 (0)