Prism's ILoggerFacade provides logging of all internal Prism errors, and a quick and easy way for your WPF, UWP, or Xamarin Forms app to introduce logging throughout your ViewModels and Services. The implementation of ILoggerFacade is really left to the developer to determine how you want to handle your logging. Using the Logging Plugins will allow you to rapidly configure remote network based logging.
NOTE These packages only take a dependency on Prism.Core and as such will work in any project using Prism.
Package | NuGet | MyGet |
---|---|---|
Prism.Logging.Common | ||
Prism.Logging.Graylog | ||
Prism.Logging.Loggly | ||
Prism.Logging.Syslog |
If this project helped you reduce time to develop and made your app better, please help support this project.
The Plugin supports various Network based Logging providers to better assist you in collecting data on your apps.
The SocketLogger is configurable to send messages using any Socket Type you choose. Typically you would choose Udp or Tcp. This works great for simple solutions where you simply want to receive logging messages over the network.
public class SocketOptions : ISocketLoggerOptions
{
// e.g. 192.168.0.100
// e.g. logging.contoso.com
public string HostOrIp => Secrets.LoggingHost;
public int Port => 12345;
public ProtocolType ProtocolType => ProtocolType.Udp;
}
public class App : PrismApplication
{
protected override void RegisterTypes()
{
Container.Register<ISocketLoggerOptions, SocketOptions>();
Container.Register<ILoggerFacade, SocketLogger>();
}
}
The Syslog package will enable you to send your logging messages to the Syslog Server of your choice, and works great with Visual Syslog Server.
public class AwesomeAppOptions : ISyslogOptions
{
// e.g. 192.168.0.100
// e.g. logging.contoso.com
public string HostNameOrIp => Secrets.LoggingHost;
// If this is null, the SyslogLogger will use port 514
public int? Port => int.Parse(Secrets.LoggingPort);
public string AppNameOrTag => "AwesomeApp"
}
public class App : PrismApplication
{
protected override void RegisterTypes()
{
Container.Register<ISyslogOptions, AwesomeAppOptions>();
Container.Register<ILoggerFacade, SyslogLogger>();
}
}
Loggly offers both free and paid Logging as a Service plans. The Loggly package will allow you to choose from either their Syslog implementation or Rest service.
NOTE By default we will send all requests to logs-01.loggly.com
. To override this you will need to inherit from the Logging class.
- For
LogglyHttpLogger
you will need to overrideLogglyBaseUri
's default value ofhttps://logs-01.loggly.com
- For
LogglySyslogLogger
you will need to implement a Logger class that derives fromLogglySyslogLogger
and update theHostNameOrIp
property.
public class LogglyOptions : ILogglyOptions
{
public string Token => Secrets.LogglyToken;
public string AppName => "AwesomeApp";
public IEnumerable<string> Tags => new string[]
{
"sample"
};
}
public class App : PrismApplication
{
protected override void RegisterTypes()
{
// Used by both the LogglyHttpLogger and LogglySyslogLogger
Container.Register<ILogglyOptions, LogglyOptions>();
Container.Register<ILoggerFacade, LogglyHttpLogger>();
// Or
Container.Register<ILoggerFacade, LogglySyslogLogger>();
}
}
Graylog is a very popular Logging platform which will accept Syslog messages. In addition to the Syslog Messages, you can also choose to use the Graylog package to take advantage of the Graylog REST Api and GELF Log Messages.
public class GelfOptions : IGelfOptions
{
// e.g. http://graylog.example.org:12202
public Uri Host => new Uri(Secrets.GraylogHost);
}
public class App : PrismApplication
{
protected override void RegisterTypes()
{
Container.Register<IGelfOptions, GelfOptions>();
Container.Register<ILoggerFacade, GelfLogger>();
}
}