Today I am going to show how to print out assemblies used by the running application. This information may be useful for logs and can be collected on application/service start.
System.Diagnostics has Process class that I am going to use to get information about current process and its modules.
System.Diagnostics has Process class that I am going to use to get information about current process and its modules.
Below is a snippet of the console application that prints out information to console.
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
using System; | |
using System.Diagnostics; | |
namespace ConsoleApplication | |
{ | |
public class Program | |
{ | |
public static void Main(string[] args) | |
{ | |
Process oProcess = Process.GetCurrentProcess( ); | |
Console.WriteLine( string.Format( "Process: {0} ({1})", | |
oProcess.ProcessName, oProcess.Id ) ); | |
Console.WriteLine( ); | |
Console.WriteLine( "MODULES:" ); | |
Console.WriteLine( "________" ); | |
foreach ( ProcessModule oModule in oProcess.Modules ) | |
{ | |
Console.WriteLine( string.Format( "{0} ({1})", | |
oModule.ModuleName, oModule.FileName ) ); | |
} | |
} | |
} | |
} |