Created
February 21, 2013 16:56
-
-
Save joeletizia/5006192 to your computer and use it in GitHub Desktop.
Logging class
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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