11

I have a program that I need to send some logs into Kiwi Syslog Server. I have looked around the net for a guide in c#, but I found nothing. I would like to have an easy to understand explanation of how to do it.

Whenever someone clicks on a button or does something important, I just want to be able to write a log entry for it. So, really all I need is an example on how you send entries to the Syslog Server.

I don't have any example code of what I already did because I found nothing that I can show off. I hope that i don't break the rules of this site by not showing any code already. But believe me, I tried to look around the net for it.

Thanks a lot for your help guys!

Shiva
  • 20,575
  • 14
  • 82
  • 112
Alon M
  • 1,583
  • 7
  • 30
  • 44

1 Answers1

13

There's an awesome open-source SysLog Library for .Net: SyslogNet.

Here's an example where I create a sender, create a message and send it:

_syslogSender = new SyslogUdpSender("localhost",514);
_syslogSender.Send(
    new SyslogMessage(
        DateTime.Now,
        Facility.SecurityOrAuthorizationMessages1,
        Severity.Informational,
        Environment.MachineName,
        "Application Name",
        "Message Content"),
    new SyslogRfc3164MessageSerializer());
i3arnon
  • 113,022
  • 33
  • 324
  • 344
  • Which code did you put into your code, i mean which dll and if you odnt mind puting "this is the meesage" into the meesage place – Alon M Jan 06 '14 at 14:18
  • I added a nuget. Do you know how to do that. Visual studio automatically downloads and adds everything you need. – i3arnon Jan 06 '14 at 14:29
  • Visual stuido should add me automatically if added this code to my code? how? – Alon M Jan 06 '14 at 14:37
  • You need to install the nugget. In the link I added there are explanations on how to add a nugget. You can do that with a right click on your project and manage nugget extensions. One you find the nugget and install it then you can use this code. – i3arnon Jan 06 '14 at 14:41
  • i am looking for nuget in the vs but cant find this one, how can i do that? i have added syslog.net from nuget, what now? – Alon M Jan 06 '14 at 14:46
  • If you added it.. Just write the code like I showed. Create a serializer, a sender, a message and send it. – i3arnon Jan 06 '14 at 14:51
  • 1
    You can't just copy my code.. You need to write it according to your needs. If you have troubles with your code you need a new question and show your code so everybody can help you. – i3arnon Jan 06 '14 at 15:39
  • And I gave you one. Which I guarantee works. If you have difficulties using the library you need to specify code and errors in a new question. People won't read the comments to help you... – i3arnon Jan 06 '14 at 15:54
  • Ok i will, 1. Error 4 Cannot implicitly convert type 'SyslogNet.Client.Serialization.SyslogRfc3164MessageSerializer' to 'SyslogNet.Client.Transport.SyslogUdpSender' C:\code\Customers\FIBI\PWFileUploader\PWFileUploaderApplication\UploadForm.cs 90 29 PWFileUploaderApplication 2. the name notification does not exist in the cuurent contex. and more – Alon M Jan 06 '14 at 15:58
  • @AlonM I updated the code.. It should remove most of your errors. – i3arnon Jan 06 '14 at 16:18
  • @i3arnon I made a small console application in C# and installed the Install-Package SyslogNet.Client and ran your snippet ... but nothing appears in my Visual Syslog server... – abmv May 27 '17 at 04:25