Progstr.Log is a service that collects and manages programmer log entries in the cloud. Most web applications log errors and special external events generated by users or third party systems. Progstr.Log takes away the pain of complex logging system configurations, provides a centralized location for all your log entries and helps you analyze the data you've collected over time. progstr-dotnet is the Microsoft .NET client library that collects log entries and transports them to Progstr data store.
#Installation
Download the distribution from the Downloads area.
Progstr.Log.dll is a regular .NET assembly that you need to refer from your application. Here is how you integrate it in your project:
- Sign up for Progstr.Log and obtain an API token. That token is used to identify you against the service. Keep it secret and do not share it with anyone unless you want to let them log messages on your behalf.
- Download the binary distribution or compile progstr-dotnet from source. Copy Progstr.Log.dll to your project and add a reference.
- Configure the API token by adding a "progstr.log.apitoken" entry to the appSettings section in your application config file (or the root web.config file for your web application):
<appSettings> <add key="progstr.log.apitoken" value="6f413b64-a8e1-4e25-b9e6-d83acf26ccba" /> </appSettings>
Alternatively, you can use the code-based configuration and just set the `LogSettings.ApiToken` static property before logging anything.
#Getting started
There are four log severity levels that you can use to log events of different importance:
- Info: used to log general information events that can be used for reference or troubleshooting if needed.
- Warning: something odd happened and somebody needs to know about it.
- Error: something failed and needs to be fixed.
- Fatal: the entire application or a critical part of it is not working at all.
To log an event you need to obtain an object implementing the ILog interface and call some of its Info/Warning/Error/Fatal methods. The easiest way to do that is to use the Log() extension method:
using Progstr.Log;
...
...
this.Log().Info(message);
...
this.Log().Warning(message);
...
this.Log().Error(message);
...
this.Log().Fatal(message);
Most logging libraries require that you initialize a log object with the current class and store it in a static field in that class where you can reuse it. We need a reference to that class, so that we can use its full name as a log source and easily distinguish which message got logged from which class. Modern C# lets us hide that complexity away by using the Log() extension method.
On some occasions it is not possible to use the Log() extension method. The most common scenario would be when logging from a static method. In that case, you can obtain an ILog object by calling the Logs.Get() static method:
using Progstr.Log;
...
...
Logs.Get<MyClass>().Info(message);
- Microsoft .NET 3.5 and later
- Mono 2.6.7 and later.
Available online here.