What does the database log keep track of?

I am new to SQL Server and wondered what is the difference between SQL Server log and user log (in my case using log4net)? I assume that there is a choice on what needs to be recorded using log4net , but what things are automatically logged in the database? For example, if a user subscribes to my site, should I manually register this transaction or will it be written to the database log automatically? I am currently starting a project and I want to find out exactly what I have to worry about when registering.

thanks

+4
source share
6 answers

Apples and oranges.

Log4net and other custom “logging” are just a way to capture the events that the application reports. The "journal" in this context refers to the fact that the storage is used by this infrastructure to store information about these events.

On the other hand, the database log is something completely different. To maintain consistency and atomicity databases, use the so-called Write-Ahead-Log protocol. In WAL, all changes are first written to the log or log before they are applied to the data. This allows you to restore the journal log (journal) and return data to a consistent state, rolling back from any idle work.

Database logs have absolutely nothing to do with your application code. Any database update will be automatically registered by the engine, simply because that is how any data in the database is updated. You cannot change this, and you do not have access to what is written in the journal (strictly speaking, you can look into the journal, but you will not find any useful information for your application).

+5
source

The SQL log processes tansaction logging to roll back or send data. Usually they are processed only by someone who knows what they are doing, restoring backups or sending logs for use in backups.

Log4net and other logging logs process the logs of exceptions, warnings, or debug level information that you want to print for your own information. They can be sent to a table in a database, command window, flat file, or web service. Common logging scripts catch unhandled exceptions at the application level to help track errors or in any try catch statements writing out a stack trace.

+2
source

It tracks transactions so that it can drop them or replay them in the event of a failure. This is much more involved than simply logging.

+1
source

The two are almost completely unrelated.

The database log is used to roll back transactions, recover from failures, etc. All good things to ensure database consistency. It has updates / inserts / deletes in it - not really anything about the intention or what your application is trying to do if it does not directly affect the data in the database.

The application log, on the other hand (with Log4Net), can be extremely useful in creating and debugging your application. It is managed by you and should contain information that tracks what your application does. This is something that you can safely disable or reduce (by switching the log level) when you no longer need it.

+1
source

The SQL Server log file is actually used to maintain its own stability, but it is not very useful for regular developers. This is not what you think (and I what I thought), the list of SQL statements that were running. This is the correct format to help SQL recover from crashes or rollback transactions.

If you need to keep track of what is happening on the system, the SQL transaction log will not be useful, and it would be very difficult to get this information. Instead, I would suggest adding triggers to your tables that write information to another table, or adding code at your data level that will save you a log of what is happening. It can be as simple as wrapping the SQL command line object with your own implementation, which saved the SQL statements in log4net in addition to any normal code that it executed.

+1
source

This is the mechanism by which RMDBS can guarantee atomicity and consistency , see ACID .

0
source

Source: https://habr.com/ru/post/1301504/


All Articles