简体   繁体   中英

how to get iis logs realtime in c#

Is there a way to get IIS logs online while saving them to log files with c#? I need to create an application to receive the logs of sites defined on iis during creation and send them to another server by a method such as syslog, etc. There are various open source tools for this, but I need to create my own customized application in c# language. Can anyone guide me in this regard?

you need to add fileWatcher and get notify on line added sou you can view log as you want

Never tried to write a syslog sender(forwarder). But I can offer you some thinking.

Firstly, let's see how to send IIS logs by tools. I installed "kiwi syslog server" on the receiver-server(192.168.2.70) side and "SolarWinds EventLog forwarder for windows" on sender-server side.

On the sender-server, I enable ETW event in the IIS logging module and enable IIS-logging in the Event viewer first. (Microsoft-Windows-IIS logging/logs. right click-enable log)

在此处输入图像描述

As you can see, after this IIS log will be write into windows event when they are generated.

在此处输入图像描述

Then on the "forwarder",add a syslog server with the receiver ip and add a subscription to the IIS logging event.

在此处输入图像描述 在此处输入图像描述

Finally, we can see the IIS logs in the receiver-server when they are generated in real time. 在此处输入图像描述

So if you want to write a sender by yourself. It will be easy if you consume IIS-logging windows event. It can notify your application when logs are generated and bring with full log information.

After that you need to format UDP message and send them to the target IP by port 514.These 2 package may help you with this work. 在此处输入图像描述

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM