Introduction
Hi! PB-LOG is a XML logger to track your application by entering logs of varius kinds (Info, Errors, Events and Warning) with the associated user. Now, it's available for .NET and WP7, but in the future I would want develop this project for Java and PHP. With 1.0 version, the old ways to use PB-LOG is still valid. Now, there are more ways to add, remove, check logs and users.
Background
I wanted write this small XML logger because, as each developer, I needed an easy, but powerful XML logger. I found and tried a lot of loggers, but them were difficult and complicated. PB-LOG is very easy to use and under here there's a code example.
Initialize PB-LOG:
Logger logger = new Logger();
Logger logger = new Logger(@"C:\logger.xml");
Logger logger = new Logger(true)
Logger logger = new Logger(@"C:\logger.xml", true)
For WP7, in the costructor you don't have to write the path, but directly the filename. Like this:
Logger logger = new Logger("logger.xml", true)
Add user:
User user = new User()
{
Username = "helloworld",
Rule = "Administrator"
};
logger.Users.Add(user);
logger.Users.Add("username", "rule");
Add log with and without the user:
Log logUser = new Log()
{
LogType = LogType.Info,
Message = "loading data...",
User = user
};
Log logNoUser = new Log()
{
LogType = LogType.Info,
Message = "loading data..."
};
logger.Logs.Add(logUser);
logger.Logs.Add(logNoUser);
logger.Logs.Add("message", LogType.Fatal);
logger.Logs.Add("message", "username", LogType.Fatal);
XML result:
="1.0"="utf-8"="yes"
<Logs>
<Errors />
<Warnings />
<Informations>
<Info Message="Hello, world!" Created="08/04/2012 01:58:37" User="pisolobill" />
</Informations>
<Events />
<Users>
<User Username="pisolobill" Rule="Administrator" Created="08/04/2012 01:58:07" />
</Users>
</Logs>
Users and Logs are custom collection the implement ICollection<T>. I wanted use this interface because their methods (Add, Remove, Contains, ecc.) are already know. ICollection supports queries LINQ and other methods, like this:
if(logger.Users.Exists(u => u.Username == "username" && u.Rule == "rule"))
{
logger.Users.Remove("username");
}
Log log = logger.Logs[2];
IEnumerable<Log> getWarnings = logger.Logs.Debugs;
IEnumerable<Log> linq = logger.Logs.Errors.Where(u => u.Rule == "Administrator");
This method will delete the XML file and it will dispose all resources.
How it works
PB-LOG load and write all XML data by XDocument.
Versions
04/11/2012 - PB.LOG - 0.9.7
04/24/2012 - PB.LOG - 1.0 - more features, more easy, resolve some bugs
04/29/2012 - PB.LOG - 1.5 - more fast, fixed few bugs (as in every version), more solid foundations (Thank you Alois Kraus for suggestions)
Contact me:
If you have some ideas, suggestions or other, contact me, please.
Thank you.
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.