Skip to content
Browse files

Added support to send growl notifications over network

  • Loading branch information...
1 parent 079080a commit ad6ab71c492a946fd2b6fafab2c7ca51867b6d9e @RyanFarley committed May 6, 2010
Showing with 17 additions and 8 deletions.
  1. +1 −1 DemoApp/NLog.config
  2. +16 −7 NLog.Targets.GrowlNotify/GrowlNotify.cs
View
2 DemoApp/NLog.config
@@ -11,7 +11,7 @@
</extensions>
<targets>
- <target name="growl" type="GrowlNotify" growlpassword="" />
+ <target name="growl" type="GrowlNotify" password="" host="" port="" />
</targets>
<rules>
View
23 NLog.Targets.GrowlNotify/GrowlNotify.cs
@@ -100,7 +100,20 @@ public class GrowlNotify : NLog.Target
public GrowlNotify()
{
- growl = new GrowlConnector();
+ Port = 23053;
+ }
+
+ public string Password { get; set; }
+ public string Host { get; set; }
+ public int Port { get; set; }
+
+ private void RegisterApplication()
+ {
+ if (string.IsNullOrEmpty(Host))
+ growl = new GrowlConnector(Password);
+ else
+ growl = new GrowlConnector(Password, Host, Port);
+
growl.EncryptionAlgorithm = Cryptography.SymmetricAlgorithmType.PlainText;
application = new Application("NLog");
@@ -116,14 +129,10 @@ public GrowlNotify()
growl.Register(application, new NotificationType[] { trace, debug, info, warn, error, fatal });
}
- public string GrowlPassword
- {
- get { return growl.Password; }
- set { growl.Password = value; }
- }
-
protected override void Write(LogEventInfo logEvent)
{
+ if (growl == null) RegisterApplication();
+
var notification = new Notification(application.Name, logEvent.Level.ToString(), null, string.Concat(logEvent.Level, ":", logEvent.LoggerShortName), logEvent.Message.Replace("\r\n", "\n"));
growl.Notify(notification);
}

0 comments on commit ad6ab71

Please sign in to comment.
Something went wrong with that request. Please try again.