using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
namespace PCardAutomation
{
public class PCardLogger
{
public static PCardLogger Instance
{
get
{
if (_Instance == null)
{
lock (_SyncRoot)
{
if (_Instance == null)
_Instance = new PCardLogger();
}
}
return _Instance;
}
}
private static volatile PCardLogger _Instance;
private static object _SyncRoot = new Object();
private PCardLogger()
{
}
public StreamWriter Writer { get; set; }
public StreamWriter WriterGlobalLog { get; set; }
public string LogPath { get; set; }
public string LogFileName { get; set; }
public string LogFileExtension { get; set; }
public string LogFile { get { return LogFileName + LogFileExtension; } }
public string LogFullPath { get { return Path.Combine(LogPath, LogFile); } }
public bool LogExists { get { return File.Exists(LogFullPath); } }
public void WriteLineToLog(String inLogMessage)
{
WriteToLog(inLogMessage + Environment.NewLine);
}
public void WriteToLog(String inLogMessage)
{
if (!Directory.Exists(LogPath))
{
Directory.CreateDirectory(LogPath);
}
using (Writer = new StreamWriter(LogFullPath, true))
{
Writer.Write(inLogMessage);
}
}
public static void WriteLine(String inLogMessage)
{
Instance.WriteLineToLog(inLogMessage);
}
public static void Write(String inLogMessage)
{
Instance.WriteToLog(inLogMessage);
}
}
}
=============================================
WRITING(CALLING THE CLASS) THE LOG:
PCardAutomation.PCardLogger.Instance.LogFileName = "Global_PCardLog_" + DateTime.Now.ToString("yyyyMMdd"); ;
PCardAutomation.PCardLogger.Write(DateTime.Now + Environment.NewLine);
PCardAutomation.PCardLogger.Write("******************************" + Environment.NewLine);
PCardAutomation.PCardLogger.Write("******************************" + Environment.NewLine);
PCardAutomation.PCardLogger.Write("ANNUAL CARD :" + Environment.NewLine);
PCardAutomation.PCardLogger.Write("******************************" + Environment.NewLine);
PCardAutomation.PCardLogger.Write("******************************" + Environment.NewLine);
PCardAutomation.PCardLogger.Write("" + Environment.NewLine);
PCardAutomation.PCardLogger.Write(ex.ToString() + Environment.NewLine);
PCardAutomation.PCardLogger.Write("" + Environment.NewLine);
PCardAutomation.PCardLogger.Write("******************************" + Environment.NewLine);
PCardAutomation.PCardLogger.Write("******************************" + Environment.NewLine);
PCardAutomation.PCardLogger.Write("" + Environment.NewLine);
Tuesday, December 1, 2015
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment