Wasp3D / C# : Generate Ad Log file

Published 4 months ago, has comments


private void logIt(string adName){
     		
     		
     		string time = DateTime.Now.ToString("hh:mm:ss"); // includes leading zeros
			string date = DateTime.Now.ToString("dd.MM.yyyy"); // includes leading zeros
			
			string txtLine = date+","+time+","+adName;

			string directory = @"C:\Logs\"+date;
     		if(!Directory.Exists(directory))
			{
			    Directory.CreateDirectory(directory);
			}
			
			string path = directory+@"\AdLog_"+adName+"_"+date+".csv";
			if(!File.Exists(path))
		    {
		        File.Create(path).Dispose();
		      	using( TextWriter tw = new StreamWriter(path))
		        {
		          tw.WriteLine("Date,Time,AdName");
		          tw.WriteLine(txtLine);
		          tw.Close();
		        }
		
			}
		
		    else if (File.Exists(path))
		    {
		        using(TextWriter tw = new StreamWriter(path,true))
		        {
		          tw.WriteLine(txtLine);
		          tw.Close(); 
		        }
		    }
	
     	}