-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Removed Diagnostics.EventLog and added functions to create session an…
…d retrieve log data
- Loading branch information
Showing
27 changed files
with
1,864 additions
and
1,201 deletions.
There are no files selected for viewing
234 changes: 117 additions & 117 deletions
234
src/EventLogExpert.EventDbTool/CreateDatabaseCommand.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,120 +1,120 @@ | ||
// // Copyright (c) Microsoft Corporation. | ||
// // Licensed under the MIT License. | ||
|
||
using EventLogExpert.Eventing.EventProviderDatabase; | ||
using EventLogExpert.Eventing.Providers; | ||
using System.CommandLine; | ||
|
||
namespace EventLogExpert.EventDbTool; | ||
|
||
public class CreateDatabaseCommand : DbToolCommand | ||
{ | ||
public static Command GetCommand() | ||
{ | ||
var createDatabaseCommand = new Command( | ||
name: "create", | ||
description: "Creates a new event database."); | ||
var fileArgument = new Argument<string>( | ||
name: "file", | ||
description: "File to create. Must have a .db extension."); | ||
var filterOption = new Option<string>( | ||
name: "--filter", | ||
description: "Only providers matching specified regex string will be added to the database."); | ||
var skipProvidersInFileOption = new Option<string>( | ||
name: "--skip-providers-in-file", | ||
description: "Any providers found in the specified database file will not be included in the new database. " + | ||
"For example, when creating a database of event providers for Exchange Server, it may be useful " + | ||
"to provide a database of all providers from a fresh OS install with no other products. That way, all the " + | ||
"OS providers are skipped, and only providers added by Exchange or other installed products " + | ||
"would be saved in the new database."); | ||
var verboseOption = new Option<bool>( | ||
name: "--verbose", | ||
description: "Enable verbose logging. May be useful for troubleshooting."); | ||
|
||
createDatabaseCommand.AddArgument(fileArgument); | ||
createDatabaseCommand.AddOption(filterOption); | ||
createDatabaseCommand.AddOption(skipProvidersInFileOption); | ||
createDatabaseCommand.AddOption(verboseOption); | ||
createDatabaseCommand.SetHandler((fileOptionValue, filterOptionValue, verboseOptionValue, skipProvidersInFileOption) => | ||
{ | ||
CreateDatabase(fileOptionValue, filterOptionValue, verboseOptionValue, skipProvidersInFileOption); | ||
}, | ||
fileArgument, filterOption, verboseOption, skipProvidersInFileOption); | ||
|
||
return createDatabaseCommand; | ||
} | ||
|
||
public static void CreateDatabase(string path, string filter, bool verboseLogging, string skipProvidersInFile) | ||
{ | ||
if (File.Exists(path)) | ||
{ | ||
Console.WriteLine($"Cannot create database because file already exists: {path}"); | ||
return; | ||
} | ||
|
||
if (Path.GetExtension(path) != ".db") | ||
{ | ||
Console.WriteLine("File extension must be .db."); | ||
return; | ||
} | ||
|
||
var skipProviderNames = new HashSet<string>(); | ||
|
||
if (skipProvidersInFile != null) | ||
{ | ||
if (!File.Exists(skipProvidersInFile)) | ||
{ | ||
Console.WriteLine($"File not found: {skipProvidersInFile}"); | ||
} | ||
|
||
using var skipDbContext = new EventProviderDbContext(skipProvidersInFile, readOnly: true); | ||
foreach (var provider in skipDbContext.ProviderDetails) | ||
{ | ||
skipProviderNames.Add(provider.ProviderName); | ||
} | ||
|
||
Console.WriteLine($"Found {skipProviderNames.Count} providers in file {skipProvidersInFile}. " + | ||
"These will not be included in the new database."); | ||
} | ||
|
||
var providerNames = GetLocalProviderNames(filter); | ||
if (!providerNames.Any()) | ||
{ | ||
Console.WriteLine($"No providers found matching filter {filter}."); | ||
return; | ||
} | ||
|
||
var providerNamesNotSkipped = providerNames.Where(name => !skipProviderNames.Contains(name)).ToList(); | ||
|
||
var numberSkipped = providerNames.Count - providerNamesNotSkipped.Count; | ||
if (numberSkipped > 0) | ||
{ | ||
Console.WriteLine($"{numberSkipped} providers were skipped due to being present in the specified database."); | ||
} | ||
|
||
using var dbContext = new EventProviderDbContext(path, readOnly: false); | ||
|
||
LogProviderDetailHeader(providerNamesNotSkipped); | ||
|
||
foreach (var providerName in providerNamesNotSkipped) | ||
{ | ||
var provider = new EventMessageProvider(providerName, verboseLogging ? (s, log) => Console.WriteLine(s) : (s, log) => { }); | ||
var details = provider.LoadProviderDetails(); | ||
if (details != null) | ||
{ | ||
dbContext.ProviderDetails.Add(details); | ||
|
||
LogProviderDetails(details); | ||
|
||
details = null; | ||
} | ||
} | ||
|
||
Console.WriteLine(); | ||
Console.WriteLine("Saving database. Please wait..."); | ||
|
||
dbContext.SaveChanges(); | ||
|
||
Console.WriteLine("Done!"); | ||
} | ||
} | ||
//using EventLogExpert.Eventing.EventProviderDatabase; | ||
//using EventLogExpert.Eventing.Providers; | ||
//using System.CommandLine; | ||
|
||
//namespace EventLogExpert.EventDbTool; | ||
|
||
//public class CreateDatabaseCommand : DbToolCommand | ||
//{ | ||
// public static Command GetCommand() | ||
// { | ||
// var createDatabaseCommand = new Command( | ||
// name: "create", | ||
// description: "Creates a new event database."); | ||
// var fileArgument = new Argument<string>( | ||
// name: "file", | ||
// description: "File to create. Must have a .db extension."); | ||
// var filterOption = new Option<string>( | ||
// name: "--filter", | ||
// description: "Only providers matching specified regex string will be added to the database."); | ||
// var skipProvidersInFileOption = new Option<string>( | ||
// name: "--skip-providers-in-file", | ||
// description: "Any providers found in the specified database file will not be included in the new database. " + | ||
// "For example, when creating a database of event providers for Exchange Server, it may be useful " + | ||
// "to provide a database of all providers from a fresh OS install with no other products. That way, all the " + | ||
// "OS providers are skipped, and only providers added by Exchange or other installed products " + | ||
// "would be saved in the new database."); | ||
// var verboseOption = new Option<bool>( | ||
// name: "--verbose", | ||
// description: "Enable verbose logging. May be useful for troubleshooting."); | ||
|
||
// createDatabaseCommand.AddArgument(fileArgument); | ||
// createDatabaseCommand.AddOption(filterOption); | ||
// createDatabaseCommand.AddOption(skipProvidersInFileOption); | ||
// createDatabaseCommand.AddOption(verboseOption); | ||
// createDatabaseCommand.SetHandler((fileOptionValue, filterOptionValue, verboseOptionValue, skipProvidersInFileOption) => | ||
// { | ||
// CreateDatabase(fileOptionValue, filterOptionValue, verboseOptionValue, skipProvidersInFileOption); | ||
// }, | ||
// fileArgument, filterOption, verboseOption, skipProvidersInFileOption); | ||
|
||
// return createDatabaseCommand; | ||
// } | ||
|
||
// public static void CreateDatabase(string path, string filter, bool verboseLogging, string skipProvidersInFile) | ||
// { | ||
// if (File.Exists(path)) | ||
// { | ||
// Console.WriteLine($"Cannot create database because file already exists: {path}"); | ||
// return; | ||
// } | ||
|
||
// if (Path.GetExtension(path) != ".db") | ||
// { | ||
// Console.WriteLine("File extension must be .db."); | ||
// return; | ||
// } | ||
|
||
// var skipProviderNames = new HashSet<string>(); | ||
|
||
// if (skipProvidersInFile != null) | ||
// { | ||
// if (!File.Exists(skipProvidersInFile)) | ||
// { | ||
// Console.WriteLine($"File not found: {skipProvidersInFile}"); | ||
// } | ||
|
||
// using var skipDbContext = new EventProviderDbContext(skipProvidersInFile, readOnly: true); | ||
// foreach (var provider in skipDbContext.ProviderDetails) | ||
// { | ||
// skipProviderNames.Add(provider.ProviderName); | ||
// } | ||
|
||
// Console.WriteLine($"Found {skipProviderNames.Count} providers in file {skipProvidersInFile}. " + | ||
// "These will not be included in the new database."); | ||
// } | ||
|
||
// var providerNames = GetLocalProviderNames(filter); | ||
// if (!providerNames.Any()) | ||
// { | ||
// Console.WriteLine($"No providers found matching filter {filter}."); | ||
// return; | ||
// } | ||
|
||
// var providerNamesNotSkipped = providerNames.Where(name => !skipProviderNames.Contains(name)).ToList(); | ||
|
||
// var numberSkipped = providerNames.Count - providerNamesNotSkipped.Count; | ||
// if (numberSkipped > 0) | ||
// { | ||
// Console.WriteLine($"{numberSkipped} providers were skipped due to being present in the specified database."); | ||
// } | ||
|
||
// using var dbContext = new EventProviderDbContext(path, readOnly: false); | ||
|
||
// LogProviderDetailHeader(providerNamesNotSkipped); | ||
|
||
// foreach (var providerName in providerNamesNotSkipped) | ||
// { | ||
// var provider = new EventMessageProvider(providerName, verboseLogging ? (s, log) => Console.WriteLine(s) : (s, log) => { }); | ||
// var details = provider.LoadProviderDetails(); | ||
// if (details != null) | ||
// { | ||
// dbContext.ProviderDetails.Add(details); | ||
|
||
// LogProviderDetails(details); | ||
|
||
// details = null; | ||
// } | ||
// } | ||
|
||
// Console.WriteLine(); | ||
// Console.WriteLine("Saving database. Please wait..."); | ||
|
||
// dbContext.SaveChanges(); | ||
|
||
// Console.WriteLine("Done!"); | ||
// } | ||
//} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,50 +1,50 @@ | ||
// // Copyright (c) Microsoft Corporation. | ||
// // Licensed under the MIT License. | ||
|
||
using EventLogExpert.Eventing.Providers; | ||
using System.CommandLine; | ||
//using EventLogExpert.Eventing.Providers; | ||
//using System.CommandLine; | ||
|
||
namespace EventLogExpert.EventDbTool; | ||
//namespace EventLogExpert.EventDbTool; | ||
|
||
public class ShowLocalCommand : DbToolCommand | ||
{ | ||
public static Command GetCommand() | ||
{ | ||
var showProvidersCommand = new Command( | ||
name: "showlocal", | ||
description: "List the event providers on the local machine."); | ||
var filterOption = new Option<string>( | ||
name: "--filter", | ||
description: "Filter for provider names matching the specified regex string."); | ||
var verboseOption = new Option<bool>( | ||
name: "--verbose", | ||
description: "Verbose logging. May be useful for troubleshooting."); | ||
showProvidersCommand.AddOption(filterOption); | ||
showProvidersCommand.AddOption(verboseOption); | ||
showProvidersCommand.SetHandler((filterOptionValue, verboseOptionValue) => | ||
{ | ||
ShowProviderInfo(filterOptionValue, verboseOptionValue); | ||
}, | ||
filterOption, verboseOption); | ||
//public class ShowLocalCommand : DbToolCommand | ||
//{ | ||
// public static Command GetCommand() | ||
// { | ||
// var showProvidersCommand = new Command( | ||
// name: "showlocal", | ||
// description: "List the event providers on the local machine."); | ||
// var filterOption = new Option<string>( | ||
// name: "--filter", | ||
// description: "Filter for provider names matching the specified regex string."); | ||
// var verboseOption = new Option<bool>( | ||
// name: "--verbose", | ||
// description: "Verbose logging. May be useful for troubleshooting."); | ||
// showProvidersCommand.AddOption(filterOption); | ||
// showProvidersCommand.AddOption(verboseOption); | ||
// showProvidersCommand.SetHandler((filterOptionValue, verboseOptionValue) => | ||
// { | ||
// ShowProviderInfo(filterOptionValue, verboseOptionValue); | ||
// }, | ||
// filterOption, verboseOption); | ||
|
||
return showProvidersCommand; | ||
} | ||
// return showProvidersCommand; | ||
// } | ||
|
||
public static void ShowProviderInfo(string filter, bool verbose) | ||
{ | ||
var providerNames = GetLocalProviderNames(filter); | ||
// public static void ShowProviderInfo(string filter, bool verbose) | ||
// { | ||
// var providerNames = GetLocalProviderNames(filter); | ||
|
||
LogProviderDetailHeader(providerNames); | ||
foreach (var providerName in providerNames) | ||
{ | ||
var provider = new EventMessageProvider(providerName, verbose ? (s, log) => Console.WriteLine(s) : (s, log) => { }); | ||
var details = provider.LoadProviderDetails(); | ||
if (details != null) | ||
{ | ||
LogProviderDetails(details); | ||
// LogProviderDetailHeader(providerNames); | ||
// foreach (var providerName in providerNames) | ||
// { | ||
// var provider = new EventMessageProvider(providerName, verbose ? (s, log) => Console.WriteLine(s) : (s, log) => { }); | ||
// var details = provider.LoadProviderDetails(); | ||
// if (details != null) | ||
// { | ||
// LogProviderDetails(details); | ||
|
||
details = null; | ||
} | ||
} | ||
} | ||
} | ||
// details = null; | ||
// } | ||
// } | ||
// } | ||
//} |
Oops, something went wrong.