///<summary>
 /// Log to the audit sub-system that a specific category event has occurred with optional
 /// message.
 ///</summary>
 ///<param name="category">A category usually named in <see cref="AuditNames"/></param>
 ///<param name="message">A string message to include with the audited event.</param>
 public void Log(string category, string message)
 {
     try
     {
         EventLogHelper.WriteInformation("Health.Direct.Audit",
                                         string.Format("AUDIT: {0} - {1}", category, message));
     }
     catch (Exception ex)
     {
         Diagnostics.Log.For(this).Warn("While auditing", ex);
     }
 }
Example #2
0
        /// <summary>
        /// This is a utility method to convert the values found in the LogFileSection
        /// to <see cref="LogFileSettings"/> and to substitute the appearance of a '~'
        /// for a call to <see cref="HttpServerUtility.MapPath"/> if this is run inside
        /// of a web context, or use the <see cref="Environment.CurrentDirectory"/>.
        /// </summary>
        /// <remarks>This assumes that there is &lt;logging /&gt; section in the app.config </remarks>
        /// <returns>A <see cref="LogFileSettings"/> object.</returns>
        public static LogFileSettings GetAsSettings()
        {
            LogFileSection section = (LogFileSection)ConfigurationManager.GetSection("logging");

            if (section == null)
            {
                return(null);
            }

            LogFileSettings settings = section.ToSettings();

            if (settings.DirectoryPath.Contains("~"))
            {
                string appDirectory = HostingEnvironment.ApplicationPhysicalPath ?? Environment.CurrentDirectory;
                settings.DirectoryPath = settings.DirectoryPath.Replace("~", appDirectory);
            }

            EventLogHelper.WriteInformation(settings.EventLogSource,
                                            "Writing log file to " + settings.DirectoryPath);

            return(settings);
        }