Files
Aaru/DiscImageChef.Core/Logging/DumpLog.cs

149 lines
6.4 KiB
C#
Raw Normal View History

2017-11-20 05:07:16 +00:00
// /***************************************************************************
// The Disc Image Chef
// ----------------------------------------------------------------------------
//
// Filename : DumpLog.cs
// Author(s) : Natalia Portillo <claunia@claunia.com>
2017-11-20 05:07:16 +00:00
//
// Component : Core algorithms.
2017-11-20 05:07:16 +00:00
//
// --[ Description ] ----------------------------------------------------------
//
// Contains glue logic for writing a dump log.
2017-11-20 05:07:16 +00:00
//
// --[ License ] --------------------------------------------------------------
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as
// published by the Free Software Foundation, either version 3 of the
// License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
//
// ----------------------------------------------------------------------------
2018-12-29 17:34:38 +00:00
// Copyright © 2011-2019 Natalia Portillo
2017-11-20 05:07:16 +00:00
// ****************************************************************************/
2017-11-20 05:07:16 +00:00
using System;
using System.IO;
using System.Reflection;
2019-07-15 15:33:46 +01:00
using System.Runtime.InteropServices;
using DiscImageChef.CommonTypes.Interop;
2017-11-20 05:07:16 +00:00
using DiscImageChef.Devices;
using PlatformID = DiscImageChef.CommonTypes.Interop.PlatformID;
using Version = DiscImageChef.CommonTypes.Interop.Version;
2017-12-19 19:33:46 +00:00
2017-11-20 05:07:16 +00:00
namespace DiscImageChef.Core.Logging
{
/// <summary>
/// Creates a dump log
/// </summary>
2017-11-20 05:07:16 +00:00
public class DumpLog
{
readonly StreamWriter logSw;
/// <summary>
/// Initializes the dump log
/// </summary>
/// <param name="outputFile">Output log file</param>
/// <param name="dev">Device</param>
2017-11-20 05:07:16 +00:00
public DumpLog(string outputFile, Device dev)
{
if(string.IsNullOrEmpty(outputFile)) return;
logSw = new StreamWriter(outputFile, true);
2017-11-20 05:07:16 +00:00
logSw.WriteLine("Start logging at {0}", DateTime.Now);
2017-11-20 05:07:16 +00:00
PlatformID platId = DetectOS.GetRealPlatformID();
string platVer = DetectOS.GetVersion();
AssemblyInformationalVersionAttribute assemblyVersion =
Attribute.GetCustomAttribute(typeof(DumpLog).Assembly, typeof(AssemblyInformationalVersionAttribute)) as
AssemblyInformationalVersionAttribute;
2017-11-20 05:07:16 +00:00
logSw.WriteLine("################# System information #################");
2017-12-21 14:30:38 +00:00
logSw.WriteLine("{0} {1} ({2}-bit)", DetectOS.GetPlatformName(platId, platVer), platVer,
Environment.Is64BitOperatingSystem ? 64 : 32);
2019-07-15 15:33:46 +01:00
if(DetectOS.IsMono) logSw.WriteLine("Mono {0}", Version.GetMonoVersion());
else if(DetectOS.IsNetCore) logSw.WriteLine(".NET Core {0}", Version.GetNetCoreVersion());
else logSw.WriteLine(RuntimeInformation.FrameworkDescription);
2017-12-29 01:26:58 +00:00
logSw.WriteLine();
2017-11-20 05:07:16 +00:00
logSw.WriteLine("################# Program information ################");
logSw.WriteLine("DiscImageChef {0}", assemblyVersion?.InformationalVersion);
logSw.WriteLine("Running in {0}-bit", Environment.Is64BitProcess ? 64 : 32);
2017-12-29 01:26:58 +00:00
#if DEBUG
logSw.WriteLine("DEBUG version");
2017-12-29 01:26:58 +00:00
#endif
logSw.WriteLine("Command line: {0}", Environment.CommandLine);
logSw.WriteLine();
2017-11-20 05:07:16 +00:00
logSw.WriteLine("################# Device information #################");
2017-12-29 01:26:58 +00:00
logSw.WriteLine("Manufacturer: {0}", dev.Manufacturer);
logSw.WriteLine("Model: {0}", dev.Model);
logSw.WriteLine("Firmware revision: {0}", dev.Revision);
logSw.WriteLine("Serial number: {0}", dev.Serial);
logSw.WriteLine("Removable device: {0}", dev.IsRemovable);
logSw.WriteLine("Device type: {0}", dev.Type);
logSw.WriteLine("CompactFlash device: {0}", dev.IsCompactFlash);
2017-12-29 01:26:58 +00:00
logSw.WriteLine("PCMCIA device: {0}", dev.IsPcmcia);
logSw.WriteLine("USB device: {0}", dev.IsUsb);
if(dev.IsUsb)
{
2017-12-29 01:26:58 +00:00
logSw.WriteLine("USB manufacturer: {0}", dev.UsbManufacturerString);
logSw.WriteLine("USB product: {0}", dev.UsbProductString);
logSw.WriteLine("USB serial: {0}", dev.UsbSerialString);
logSw.WriteLine("USB vendor ID: {0:X4}h", dev.UsbVendorId);
logSw.WriteLine("USB product ID: {0:X4}h", dev.UsbProductId);
}
2017-12-29 01:26:58 +00:00
logSw.WriteLine("FireWire device: {0}", dev.IsFireWire);
if(dev.IsFireWire)
{
2017-12-29 01:26:58 +00:00
logSw.WriteLine("FireWire vendor: {0}", dev.FireWireVendorName);
logSw.WriteLine("FireWire model: {0}", dev.FireWireModelName);
logSw.WriteLine("FireWire GUID: 0x{0:X16}", dev.FireWireGuid);
logSw.WriteLine("FireWire vendor ID: 0x{0:X8}", dev.FireWireVendor);
logSw.WriteLine("FireWire product ID: 0x{0:X8}", dev.FireWireModel);
2017-11-20 05:07:16 +00:00
}
2017-12-29 01:26:58 +00:00
logSw.WriteLine();
logSw.WriteLine("######################################################");
logSw.WriteLine();
logSw.WriteLine("################ Dumping progress log ################");
logSw.Flush();
2017-11-20 05:07:16 +00:00
}
/// <summary>
/// Adds a new line to the dump log
/// </summary>
/// <param name="format">Format string</param>
/// <param name="args">Arguments</param>
2017-11-20 05:07:16 +00:00
public void WriteLine(string format, params object[] args)
{
if(logSw == null) return;
string text = string.Format(format, args);
logSw.WriteLine("{0:s} {1}", DateTime.Now, text);
logSw.Flush();
2017-11-20 05:07:16 +00:00
}
/// <summary>
/// Finishes and closes the dump log
/// </summary>
2017-11-20 05:07:16 +00:00
public void Close()
{
logSw?.WriteLine("######################################################");
logSw?.WriteLine("End logging at {0}", DateTime.Now);
logSw?.Close();
2017-11-20 05:07:16 +00:00
}
}
2017-12-19 20:33:03 +00:00
}