Hi all,
i have a class called ActivityLog.cs and this basically creates a log of whats going on in my console app.
i construct it like:
ActivityLog Activity = new ActivityLog();
then you use it like
activity.log("this is one entry");
and when the program is done you can mail out the log like
activity.Email("me@me.com","me@you.com","the log file");
My program uses three different classes, right now the activity log only works with the first, well it will work with all three but only if i construct a new log file for each class, i was hoping someone could help me figure out a way to pass the log back and forth during the execution of the different classes. I am familiar with the Facade design pattern for ASP.NET pages, but this is a console application that does not utilize the Session variables.
Any ideas Its easy enough to pass the log to the new classes (i can even add it to the constructors) however the methods in the new classes all have to return int's and once i get the log to the new class, i dont know how to get it back.
thanks in advance,
mcm

Maintaining an Activity Log over multiple classes
Joe Case
You might consider using log4net (http://logging.apache.org/log4net/) instead of rolling your own.
Chris Lively
Steve Graber
I would agree with that too but if you want to pass the class around the classes then take a look at this on passing objects around classes
http://forums.microsoft.com/MSDN/ShowPost.aspx PostID=729974&SiteID=1
xRuntime
yes i will make them static i believe,
thanks for the tips.
mcm
Ian1971
try this perhaps:
public static class ActivityLog{
public static void ActivityLog(string filepath, bool UseUTC)
public static void Log(string entry)
public static void Log(string entry, LogEntryType entrytype)
public static string GetString()
//public static override string ToString() -> not sure you can override toString when in static, so perhaps create a method called ToString instead
pubc static string ToString()
public static bool Save()
public static bool SaveAs(string fileName)
public static bool Email(string toaddr, string fromaddr, string subject, string body, bool inMsg, bool AsAttach)
}
MarkDu
thanks for the reply,
below are the various constructors i have in that class.
public class ActivityLog{
public ActivityLog
public ActivityLog(string filepath, bool UseUTC)
public void Log(string entry)
public void Log(string entry, LogEntryType entrytype)
public string GetString()
public override string ToString()
public bool Save()
public bool SaveAs(string fileName)
public bool Email(string toaddr, string fromaddr, string subject, string body, bool inMsg, bool AsAttach)
}
thats pretty much all of it, theres also a public struct LogEntry above the class definition.
thanks,
mcm
}
Jared2000
ryan.rogers
I'm sure you should be ok declaring it with parameters
public static myClass(type params)
{
}
then for any other methods:
public static void myMethod(type param1) { ... }
can you show us the signatures of the constructor and methods
RTodd
i am attempting to convert this class to be static, however i get errors saying that the static constructors have to be parameterless, since i dont want to re-write this whole log class as its pretty robust am i SOL
thanks,
mcm