Logging web services operations behind load balancer - c#

I developed some web services will be installed on 4 different servers behind a load balancer mantains sessions.
I'm using c# and log4net.
The appenders are a RollingFileAppender and an AdoNetAppender.
I read from https://logging.apache.org/log4net/release/faq.html (section How do I get multiple process to log to the same file?)
If you use RollingFileAppender things become even worse as several
process may try to start rolling the log file concurrently.
RollingFileAppender completely ignores the locking model when rolling
files, rolling files is simply not compatible with this scenario.
I can't use RollingFileAppender with MinimalLock. But I want to log from the different servers to the same file.
I prefer to keep log4net but I'm interested also in other solution (not the linux syslog one). No commercial solutions allowed for costs.

Unfortunately, you'll discover that logging directly to the same file from multiple processes is not a very feasible option.
You have several alternatives:
Log to different files - each server can have a separate file
Send all your logs to one application, which will then log to the files. This will make your logging more brittle and require extra development effort.
Log to a database - databases are designed to have multiple processes writing to them at once
Log to a logging server - Seq, Stackify Retrace, and Azure Application Insights are some examples of solutions that are robust and designed to ingest logs from multiple applications - plus you get much better capabilities

Related

Storing log files on cloud

I have developed a desktop application that will be used without my presence. Therefore, my program may register different events - input, executed operations, working time. Is it possible to modify app for sending logs to any cloud for remote viewing reports?
I have accounts on Wuala and Google Drive, but not a problem to register somewhere else (DropBox? SkyDrive? I don't know what cloud will be easier for work in this situation).
Or you can suggest another, more elegant, solution.
I am using C#, .Net 2.0. Logs are simple .txt files.

Best way to read error messages from a Log4Net log file

I would like to display the log created by Log4Net on a web page in my admin interface.
Isnt there any methods available in the log4net library to read the error messages from the configured source (textfile or database)? At the moment I am using a database table to log all errors.
If not, there must be some third party libraries available that does this for me?
If you want an elegant solution to collect and search logs using log4net based logging, a syslog daemon like kiwi syslog in combination with log4net local or remote syslog appender would probably be the easiest way to do it. Logging in a database works, but in my opinion logs are of no concern to the application itself and should be kept away from it. For instance a failing database connection would probably not show up if the logs resided solely on the same database.

where to store log information from load-balanced servers

We have 2 asp.net web servers working through the LoadBalancer that are accessible externally. Earlier, for all applications we did logging into DB. Now we have 1 more app that doesn't work with DB, it is used for 'messages transferring'. On TEST environment it does logging into files into a local folder.
If we deploy it "as is" to PROD we will have 2 separate log files... that is not very good idea. Connecting to DB just for logging doesn't seem reasonable too...
Possible solution could be store log file into a shared folder somewhere on another server... but, I not sure if this is the best solution.
Please advise.
In the past, I have just stored the web logs on each machine in the farm. We then used an off the shelf piece of software (I don't recall which one it was) to periodically download the files from each machine in the farm.
This solution worked well for us - YMMV.
The feature of our "Load Balancer" is that most of the time only 1 server works (we use very cheap solution that on low load it doesn't allow really balancing, it provides availability only). So for now I will store log information in log-folder on "own" server...

How would you centralize configuration across multiple projects?

I have a solution with about 10 projects with read-only config. They are web applications, windows services, console apps, etc. All projects except for one are on the same server. Each project has 3 environments - dev, test, and production. So there are 30 different sets of configuration, each one with a decent number of settings. It's cumbersome to keep the config consistent across every app and environment.
I've noticed most of the configuration is common across each project, so I was thinking it would be good to centralize the config in some way. I read somewhere that a WCF service might be a good approach. I thought maybe a library containing a hard-coded static class might actually work OK - despite having to compile to change config. Ideally the config should come out of an actual .config file.
How would you go about centralizing config for multiple projects?
If you want to maintain the standard configuration interface, take a look at the ProtectedConfigurationProvider. This provider lets you store your configuration data outside of a standard configuration file, encrypt it however you like, or redirect requests for configuration in any way you see fit:
Redirecting Configuration with a Custom Provider - Wrox
Implementing a Protected Configuration Provider - MSDN
Protected Configuration - Blayd Software
The beauty of this approach is that nothing changes in your existing applications. They don't need to know where their configuration is stored. The retrieval of configuration data is isolated in the provider. You can store it in a central file, store it in a database, or access it via a web service. If you change your mind, you only have to update your provider. Everything else stays the same.
You could certainly set up a WCF service that has a simple operation to retrieve configuration settings, taking in the application and environment as a parameter; you could then have the service load up the correct config from a file and return it to the caller. It might be a good idea to do nested configuration files, so that common settings are only defined once at their most generic level.
A potential issue could arise if the WCF service is down when starting up one of your apps -- you would need to decide if there is default config/caching of the previous copy for this situation, or if you just don't allow apps to start up if they cannot connect.
Another thing to consider, though, is the benefit of .config files in .NET in that when they change the app can respond; you may want to have a callback WCF service that notifies clients if their configuration has been updated on the central server, so they can request a new copy and update themselves if necessary.
Since they are (almost) all on the same server you could consider providing defaults in the machine.config and/or central web.config files. I'm not normally a fan of using/changing these file but they are there... in \Windows\Micsrosoft.NET\Framework<version>\Config\
You can use a centralized configuration sever like Lygeum which permits to manage applications and environments through web console or Command Line Interface with user management and client management module, clients may be in your case web apps, console services or whatever. The server installation is simple through docker.

How to calculate bandwidth consumption for a Hosting Account using C# in ASP.Net Application?

HI all,
I am working on SaaS Hosting Software. a large number of sites are hosted on the server. I am trying to calculate bandwidth consumption, (bytes transferred in and out) using C#, described Here using the MS Log Parser.
In the above case, if the log files are deleted by the user or any administrator even, the bandwidth calculation will not be possible.
Q1: What is the standard way to measure the Bandwidth for various Hosting accounts (of websites) on a single server?
Q2: If Log parser mechanism (as described above) is used, then how to take care of the security issue? Is there some system directory or event viewer logs or something which cannot be deleted except by the System account and contains bandwidth data?
Please point me in the right direction.
Thanks
The logs your talking about can be deleted by an administrator but so can the entire site. You should probably talk to them about your need to access/use these files. You could also change IIS to log to a DB versus a file, so you can keep the data in your own repository. In addition to getting information directly from your logs, administrators may have other tools to use to monitor and report bandwidth (Firewalls, Routers, etc...). You should probably be working together with them to develop your solution.

Categories