Logging and Reporting
The Syndicated Client Experiences (SCE) Starter Kit provides two classes, Logger and CounterStore, for logging and reporting application events. In addition, the SceReader sample application contains a SampleLogger class which shows how to add file-upload capability to the Logger class.
What is the difference between the Logger and the CounterStore classes?
Logger provides methods that allow you to log events that occur in your SCE Reader application. The CounterStore class’s functionality is exposed via Logger. As its name suggests, the CounterStore class aggregates counter information for each event, which is useful for tracking information such as ad impressions and clicks. This provides a more compact representation of application events rather than logging each event separately.
The downside to tracking events using the CounterStore class instead of logging events individually is that you lose fine-grained information such as an event timestamp. If in doubt, simply use the Logger class for all your reporting needs.
How are the log files persisted?
During application shutdown, the log and counter files are persisted to disk. The log file is saved as plain text. If you want to persist the log file in a different (or encrypted) format, simply override the Logger.Flush method. New data is appended to the existing log file, so there is no need to override a Load method.
The counter file is saved in a binary format. Once again, you can save the counter information in any format you like by overriding Logger.Flush. Bear in mind that new counter data is not simply appended to the existing counter. If you override the Flush method, you will have to make sure that you can read and serialize the existing values.
Where are the log files stored?
The path for the log file is generated by combining the SceReaderSettings.LocalCacheFolder and SceReaderSettings.LogFile properties. On Vista, The log file is saved in the %userprofile%\AppData\Local\{CompanyName}\{ApplicationName}\ folder (as the file log.txt). Similarly, the path for the counter file is the local cache folder specified by SceReaderSettings.CounterFile. By default, this file is saved to the same location as the log file. (On XP, the location is %userprofile%\Local Settings\Application Data\{CompanyName}\{ApplicationName} \counter.txt.nrstat.)
By overriding SceReaderSettings property values, you can specify the CompanyName and ApplicationName which appear in the paths above.
What is the file format of the log file?
By default, the log file is a plain-text file that stores events in sequential order. The format for each event is the following:
{TimeStamp},{EventType},{EventMessage}
What events are logged by default?
The following event information is logged by the Logger class:
- Information
- Data synchronization events
- Navigation events (
LogNavigationInfo method)
- Warnings
- Errors
- Data conversion errors
- Data errors (for example, information cannot be found)
The following event information is logged by the CounterStore class:
How do I upload logs to my server?
The SCE Reader Starter Kit sample application comes with a SampleLogger class that illustrates how you can upload logs to the server. Depending on your back-end infrastructure, you might need to alter this functionality accordingly.
How do I log ad impressions and clicks?
By default, ad impressions and clicks are already logged in the counter. You can also save these in the event-based log file. There are two ways to do this, as described in the following procedures.
Option A – Override the Logger class UpdateCounter methods
- Create a new class that derives from
Logger (you can use SampleLogger in the sample application).
- Override the
UpdateCounter methods to log the data directly to the log file, as shown in the following example:
public override void UpdateCounter(string counter, string cookie)
{
Information(counter + "," + cookie);
}
- Override
OnInitializeLogger method in the ServiceProvider class to instantiate your Logger class, as shown in the following example:
protected override void OnInitializeLogger()
{
LoggerInternal = new SampleLogger();
}
For a more complete example, see the SampleServiceProvider class.
Option B – Override the AdSelector OnAdImpression and OnAdClicked methods
- Create a new class that derives from
SceReader.Data.AdSelector.
- Override the
OnAdImpression method, as shown in the following example:
public override void OnAdImpression(AdvertisementEventArgs e)
{
ServiceProvider.Logger.Information("AdImpression",
e.Advertisement.Address + "," + e.Size.Width + ", " + e.Size.Height);
}
- Override the
OnAdClicked method. It will be very similar to the previous example.
- Register your new class in the
SampleServiceProvider class, as shown in the following example:
protected override void OnInitializeAdSelector()
{
AdSelectorInternl = new MyAdSelector();
}