I have a ASP MVC project with areas and i have to log exceptions into database. But I have a problem. I must write log exceptions from each area to its own table in database. I have an idea to configure DataTargets
for all areas with CommandText
related with table name, but it seems pretty ugly. A bit more fantastic way is to get all areas on application start and build targets via some factory.
Does someone have any idea or best practices about this issue?
How do you use NLog for multiple projects in the same solution? If you want to log in other projects within the solution, just reference NLog. dll directly in each of the projects and use it. But now you only need to configure NLog in your main application.
NLog 1.0 supports asynchronous logging, but there is no good support for asynchronous exception handling. This is because wrappers targets are not capable of receiving exceptions which are raised on other threads.
nlog file can be found at: C:\Program Files (x86)\Pleasant Solutions\Pleasant Password Server\www\web. nlog.
The CommandText
property of the database target is a layout, so you could do:
<target xsi:type="Database"
name="db"
commandText="insert into ${event-properties:tablename} ... ">
and using fluent style (NLog.Fluent namespace):
logger.Info().Message("this is a message").Property("tablename", "table1").Write();
You could also use more global contexts, like GDC, MDC etc. See NLog Wiki
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With