Skip to content

Instantly share code, notes, and snippets.

@joeletizia
Created February 21, 2013 16:56
Show Gist options
  • Select an option

  • Save joeletizia/5006192 to your computer and use it in GitHub Desktop.

Select an option

Save joeletizia/5006192 to your computer and use it in GitHub Desktop.
Logging class
public class SubordinateLoggingContext
{
private static string CONNECTIONSTRING = "mongodb://connotate:[email protected]:10002/ConnotateLogs";
MongoServer mongo;
MongoDatabase db;
MongoCollection collection;
public SubordinateLog log;
public SubordinateLoggingContext()
{
mongo = new MongoClient(CONNECTIONSTRING).GetServer();
db = mongo.GetDatabase("ConnotateLogs");
collection = db.GetCollection("logs");
log = new SubordinateLog();
collection.Save(log);
}
public async void LogMessage(string message)
{
var m = new Message(message);
//log.Messages.Add(m);
WriteMessageAsync(m);
}
private void WriteMessageAsync(Message message)
{
try
{
Task.Factory.StartNew(() =>
{
collection.Update(Query.EQ("_id", log._id), Update.PushWrapped<Message>("Messages", message));
});
}
catch (Exception)
{
//eat it. logger should never throw.
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment