代码:
using Microsoft.AspNetCore.Razor.TagHelpers; using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; namespace NetCoreTestMVC2.Commons { //public class EmailTagHelper : TagHelper //{ // 示例1:<email mail-to="xxx@qq.com"></email> // public string MailTo { get; set; } // public override void Process(TagHelperContext context, TagHelperOutput output) // { // output.TagName = "a"; // output.Attributes.SetAttribute("href",$"mailto:{MailTo}"); // output.Content.SetContent(MailTo); // } // 示例2:<email>xxx@qq.com</email> // public async override Task ProcessAsync(TagHelperContext context, TagHelperOutput output) // { // output.TagName = "a"; // var content = await output.GetChildContentAsync(); // var target = content.GetContent(); // output.Attributes.SetAttribute("href", $"mailto:{target}"); // output.Content.SetContent(target); // } //} //[HtmlTargetElement(Attributes = "bold")] //[HtmlTargetElement("bold")] //public class BoldTagHelper : TagHelper //{ // //示例:<p bold>xxx</p> 或者 <bold>xxx</bold> // public override void Process(TagHelperContext context, TagHelperOutput output) // { // output.Attributes.RemoveAll("bold"); // output.PreContent.SetHtmlContent("<strong>"); // output.PostContent.SetHtmlContent("</strong>"); // } //} /// <summary> /// 条件 TagHelper /// <div condition="_SignInManager.IsSignIn(User)">xxx</div> /// 如果 condition 中返回的值是 false 则不会显示 div /// </summary> //public class ConditionTagHelper : TagHelper //{ // public bool Condition { get; set; } // public override void Process(TagHelperContext context, TagHelperOutput output) // { // if (!Condition) // { // output.SuppressOutput(); // } // } //} //前端使用TagHelper前缀,@tagHelperPrefix "tagpre:" //TagHelper 前缀,使用在标签前加上<tagpre:a>xxx</tagpre:a> }
nuget使用日志Nuget安装:Serilog/Serilog.AspNetCore/Serilog.Sinks.File/Serilog.Sinks.Console
配置:
public class Program { public static void Main(string[] args) { Log.Logger = new LoggerConfiguration() .MinimumLevel.Debug() .MinimumLevel.Override("Microsoft", LogEventLevel.Information) .Enrich.FromLogContext() .WriteTo.Console() .WriteTo.File(Path.Combine("logs", "log.txt"), rollingInterval: RollingInterval.Day) .CreateLogger() ; CreateWebHostBuilder(args).Build().Run(); } public static IWebHostBuilder CreateWebHostBuilder(string[] args) => WebHost.CreateDefaultBuilder(args) .UseSerilog() .UseStartup<Startup>(); }