How I can get information from printer about count of copy pages, who's
print pages etc. I want monitoring printers and save that information to
file log. Maybe printer has any events to do that ?
Thank's for all.
Monitoring print job
1 Answer
Know the answer? Post it. Somebody with the same question will find it here.

Tahir AnsariRank #366 · 6.8K reputationPosted Oct 29, 2023, 9:51 AM EDT
In this example, we subscribe to the
JobAddedevent of each print queue to log information about print jobs as they are added to the queue. You can also subscribe to other print job events likeJobCompleted,JobPrinted, etc., to capture additional information as needed.using System; using System.IO; using System.Printing; public class PrinterMonitor { public static void Main(string[] args) { LocalPrintServer printServer = new LocalPrintServer(); foreach (PrintQueue printQueue in printServer.GetPrintQueues()) { printQueue.JobAdded += PrintQueue_JobAdded; // Add other event handlers for print job events, if needed } Console.WriteLine("Monitoring print queues. Press Enter to exit."); Console.ReadLine(); } private static void PrintQueue_JobAdded(object sender, PrintJobInfoEventArgs e) { PrintQueue printQueue = (PrintQueue)sender; PrintSystemJobInfo job = e.PrintJobInfo; // Log the print job information to a file string logMessage = $"Print Job ID: {job.JobIdentifier}, User: {job.Submitter}, Page Count: {job.NumberOfPagesPrinted}"; LogToFile("print_job_log.txt", logMessage); } private static void LogToFile(string fileName, string message) { using (StreamWriter writer = File.AppendText(fileName)) { writer.WriteLine($"{DateTime.Now:yyyy-MM-dd HH:mm:ss}: {message}"); } } }