![]() ![]() Or, you could create a "custom" set of properties to add to a layout. For example, you might define variables for your layouts and then reference the variable in the target configuration rather than specify the layout directly. Use "variable" in your config file to simplify. Use the GlobalDiagnosticContext, MappedDiagnosticContext, and NestedDiagnosticContext to add additional context to your output. Probably the most notable items here are the ability to wildcard logger rules, the concept that multiple logger rules can "execute" for a single logging statement, and that a logger rule can be marked as "final" so subsequent rules will not execute for a given logging statement. See the NLog help for more info on exactly what each of the options means. Loggers have many configuration options: With hierarchical loggers, you can configure logging globally (the "*" or root logger), by FA (Database, Analysis, UI), or by subarea (Database.Connect, etc). Logger logger = LogManager.GetLogger("Analysis.Inventory") Īnd so on. Logger logger = LogManager.GetLogger("Analysis.Personnel") Logger logger = LogManager.GetLogger("Analysis.Financial") Logger logger = LogManager.GetLogger("Database.SQL") Logger logger = LogManager.GetLogger("Database.Query") So, you might request loggers like this: Logger logger = LogManager.GetLogger("Database.Connect") ![]() For example, you might have a "database" functional area, an "analysis" FA, and a "ui" FA. If you don't use classname-based logging, consider naming your loggers in some kind of hierarchical structure (maybe by functional area) so that you can maintain greater flexibility in your configuration. Maybe you have some cross-cutting logging concerns (performance logging). Maybe you have one function for which you really want to control the logging separately. Use non-classname-based loggers where appropriate. This gives you a high degree of granularity in your loggers and gives you great flexibility in the configuration of the loggers (control globally, by namespace, by specific logger name, etc). Use the common pattern of naming your logger based on the class Logger logger = LogManager.GetCurrentClassLogger(). Why do loggers recommend using a logger per class? Here are some general logging links from here at SO (you might have seen some or all of these already): Some of these fall into the category of general NLog (or logging) tips rather than strictly configuration suggestions. ![]()
0 Comments
Leave a Reply. |
Details
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |