Click here to Skip to main content
13,095,921 members (51,694 online)
Click here to Skip to main content
Add your own
alternative version


15 bookmarked
Posted 10 Apr 2012

PB-LOG 1.5, quick and easy XML logger

, 30 Apr 2012
Rate this:
Please Sign up or sign in to vote.
A quick and easy XML logger for .NET (WPF, ASP.NET, WP7, ecc.). You can track your application by entering logs with the associated user.


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.


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(); // basic - default name of xml file

Logger logger = new Logger(@"C:\logger.xml"); // you can decide name of xml file

Logger logger = new Logger(true) // you can decide if users will be owners of logs. in this way, when will be deleted a user, will be deleted also their logs

Logger logger = new Logger(@"C:\logger.xml", true) // you can decide name of xml file and if users will be owners of logs

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) // you can decide name of xml file and if users will be owners of logs 

Add user:

User user = new User()
   Username = "helloworld",
   Rule = "Administrator"


logger.Users.Add("username", "rule");

Add log with and without the user:

Log logUser = new Log() // log with a user
   LogType = LogType.Info,
   Message = "loading data...",
   User = user

Log logNoUser = new Log() // log without a user
   LogType = LogType.Info,
   Message = "loading data..."



logger.Logs.Add("message", LogType.Fatal);

logger.Logs.Add("message", "username", LogType.Fatal);

XML result:

<?xml version="1.0" encoding="utf-8" standalone="yes"?>
  <Errors />
  <Warnings />
    <Info Message="Hello, world!" Created="08/04/2012 01:58:37" User="pisolobill" />
  <Events />
    <User Username="pisolobill" Rule="Administrator" Created="08/04/2012 01:58:07" />

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"))

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.


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 article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

United States United States
No Biography provided

You may also be interested in...


Comments and Discussions

GeneralMy vote of 5 Pin
markin7730-Apr-12 8:16
membermarkin7730-Apr-12 8:16 
GeneralRe: My vote of 5 Pin
pisolobill30-Apr-12 8:18
memberpisolobill30-Apr-12 8:18 
GeneralMy vote of 1 Pin
Alois Kraus25-Apr-12 20:51
memberAlois Kraus25-Apr-12 20:51 
GeneralRe: My vote of 1 Pin
pisolobill26-Apr-12 1:49
memberpisolobill26-Apr-12 1:49 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.170813.1 | Last Updated 30 Apr 2012
Article Copyright 2012 by pisolobill
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid