Skip to content

Commit

Permalink
Merge pull request #30 from microsoft/jschick/check_providers_onload
Browse files Browse the repository at this point in the history
Added provider database check on load
  • Loading branch information
bill-long authored May 9, 2023
2 parents 264e0c5 + 207d753 commit 3d0836a
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 6 deletions.
4 changes: 2 additions & 2 deletions src/EventLogExpert.Library/Providers/RegistryProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ public IEnumerable<string> GetMessageFilesForLegacyProvider(string providerName)

foreach (var logSubKeyName in eventLogKey.GetSubKeyNames())
{
// Skip Security since it requires elevation
if (logSubKeyName == "Security")
// Skip Security and State since it requires elevation
if (logSubKeyName is "Security" or "State")
{
continue;
}
Expand Down
10 changes: 8 additions & 2 deletions src/EventLogExpert/MauiProgram.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
using EventLogExpert.Store;
using EventLogExpert.Store.EventLog;
using Fluxor;
using System.Diagnostics;

namespace EventLogExpert;

Expand Down Expand Up @@ -37,7 +36,14 @@ public static MauiApp CreateMauiApp()
options.AddMiddleware<LoggingMiddleware>();
});

builder.Services.AddSingleton<IEventResolver>(new EventProviderDatabaseEventResolver(Utils.Trace));
if (Utils.HasProviderDatabases())
{
builder.Services.AddSingleton<IEventResolver>(new EventProviderDatabaseEventResolver(Utils.Trace));
}
else
{
builder.Services.AddSingleton<IEventResolver, LocalProviderEventResolver>();
}

return builder.Build();
}
Expand Down
23 changes: 21 additions & 2 deletions src/EventLogExpert/Utils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,31 @@ internal class Utils
{
private static readonly long _maxLogSize = 10 * 1024 * 1024;

internal static bool HasProviderDatabases()
{
var path = Path.Join(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData),
"EventLogExpert",
"Databases");

try
{
return Directory.EnumerateFiles(path, "*.db").Any();
}
catch
{
return false;
}
}

internal static void InitTracing()
{
// Set up tracing to a file
var eventLogExpertDataFolder = Path.Join(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "EventLogExpert");
var eventLogExpertDataFolder =
Path.Join(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "EventLogExpert");

var debugLogPath = Path.Join(eventLogExpertDataFolder, "debug.log");
var fileInfo = new FileInfo(debugLogPath);

if (fileInfo.Exists && fileInfo.Length > _maxLogSize)
{
fileInfo.Delete();
Expand All @@ -26,7 +45,7 @@ internal static void InitTracing()
// Trace all exceptions
AppDomain.CurrentDomain.FirstChanceException += (o, args) =>
{
Trace($"{args.Exception}");
Trace($"{args.Exception}");
};
}

Expand Down

0 comments on commit 3d0836a

Please sign in to comment.