Where to write a log for a Windows application

I have a .NET Windows application that is deployed through ClickOnce to a web server. About 100 users at any time, all centered. I use log4net to log into the application, but I'm having trouble getting the best place to put the log.

I tried to write them to a shared network folder, but some users encountered poor I / O with this approach. I tried to enter the user temporary files folder, but this makes it difficult to extract the logs. I have not tried the event log, because I will probably have to jump over some hoops to achieve this, and I'm not sure if it is worth it. I have never tried database maintenance, but I always assumed that it would be relatively slow.

Does anyone have experience logging into a Windows application deployed in a corporate environment? Any suggestions on where I can put the magazine so that it is (1) fast, (2) reliable and (3) affordable?

+2
windows logging
Apr 07 '09 at 20:29
source share
8 answers

The problem with database logging is not speed: it is reliability. You register when things go wrong, and if something goes wrong, the chances of an inaccessible database are not in your favor.

As a rule, you want to write to a local text file and somewhere else, as a network resource or database. If you have problems with IO / speed, you can use the text file as a buffer and write logs to the resolved resource in batches. Then you periodically clear the local backup logs.

+2
Apr 07 '09 at 20:32
source share

log4net supports adding databases for some major databases. This might be a better alternative if you have the right database. Be careful, however, because it can reduce the reliability of your application if it is not managed correctly.

You can use it in conjunction with local file logging, using BufferingForwardingAppender to batch register on the network and send only when you receive a message that exceeds a certain threshold. That way, you can have enough context to track errors, but only when errors occur.

<appender name="BufferingForwardingAppender" type="log4net.Appender.BufferingForwardingAppender"> <bufferSize value="1024" /> <lossy value="true" /> <evaluator type="log4net.Core.LevelEvaluator"> <threshold value="ERROR"/> </evaluator> <appender-ref ref="DatabaseAppender" /> 

+2
Apr 07 '09 at 20:35
source share

I used log4net with ms sql databases. Typically, I host them with dedicated db on another server, if possible. Thus, if there is a problem with the application server or db, I do not lose registration.

Speed ​​has never been a problem.

+2
Apr 7 '09 at 20:35
source share

What about the ApplicationData folder? In Vista, it will be something like this:

C: \ Users \ Ray \ AppData \ Local \ MyCompanyName

If you want a central location, I would go with the database log. But, as Joel said, you need the local location to always work (or close to it) and take center stage for collecting logs when everything works fine.

+1
Apr 07 '09 at 20:32
source share

You can use a combination of local logging, and you could synchronize the logs with the central database on successful logout.

It depends on what registration you want to do and how your application works. If the logging application is a client application, then if you write to the event logs, this may not be very useful.

If you want to write to the event logs, this is pretty simple:

http://support.microsoft.com/kb/307024

One more thing: if you are looking for a place that, as you know, have access to the user, you can use isolated storage, but the fact that you tried to write to a shared folder makes me what you want one central place for your magazines, in which case the database is probably the best choice, and my best suggestion might be better for you.

+1
Apr 7 '09 at 20:36
source share

If the application is a typical two-level job, you may need to log in the database with AdoNetAppender . AdoNetAppender combines log messages in chunks of up to 100, although you probably want to configure it to record at least WARN severity events.

You can also consider entering into the data directory of all users, although this can make it just as cumbersome to retrieve the logs. Maybe it's worth adding a shortcut somewhere?

Finally, if journal accessibility issues are a common theme in your organization, you can consider a magazine collection application such as Splunk .

0
Apr 07 '09 at 20:34
source share

You can try somewhere in the CommonAppData folder - that is, CommonAppData \ YourAppName \ Logs - provided that you provide a size limit and / or periodic cleanup. People are used to periodically clean up temporary folders, but they are wary of getting started with CommonAppData, AppData, or LocalAppData.

Recording anywhere except here or in Temp will sooner or later lead to problems with Vista and higher.

If the magazines are not vital, i.e. if irreplaceable data is not lost, if someone deletes the log, I will definitely come up for a subfolder in Temp and you will have a separate task scheduler task. This is the least painful place.

0
Apr 7 '09 at 20:35
source share

In our applications, we log4net and use the common log file for all our users, in the CommonAppData directory (C: \ Documents and Settings \ All Users \ Application Data \ Company \ Product). In this case, our installer must manually set the file permissions for the directory and the log file so that all users can access it, the default permissions are only for the user installing the application.

We also write unhandled exceptions (when we can) to the event log using the top-level exception handler (using an implementation similar to: http://www.wintellect.com/cs/blogs/jclark/archive/2005/03/30/simple -main.aspx ). We use the event log, since all bets are disconnected from the state of open file streams. Again, our installer must configure the event log source in the application event log.

If you use an event log, make sure your log is very minimal. If you are registering a lot of events, since the event log can be filled out quite quickly, and the default policy for XP is to have the event log start to drop events if the log is full and the default size is relatively small (512 KB, and only overwrite events older than 7 days).

0
Apr 07 '09 at 20:43
source share



All Articles