public string Render(Project project, ProjectItem <LoggerModel> loggerProjectItem, EventModel model) { if (loggerProjectItem.ItemType != ProjectItemType.LoggerImplementation) { LogError($"{loggerProjectItem.Name} should be of ItemType {nameof(ProjectItemType.LoggerImplementation)} set but found {loggerProjectItem.ItemType}"); return(""); } var loggerModel = loggerProjectItem.Content; if (loggerModel == null) { LogError($"{loggerProjectItem?.Name ?? nameof(loggerProjectItem)} should have content of type {typeof(LoggerModel).Name}, but found {loggerProjectItem?.GetType().Name ?? "null"}"); return(""); } var eventSourceModel = loggerModel.EventSource; if (eventSourceModel == null) { LogError($"{loggerProjectItem?.Name ?? nameof(loggerProjectItem)} should have content of type {typeof(LoggerModel).Name} with property EventSource set, but found {loggerModel.EventSource?.Name ?? "null"}"); return(""); } var output = LoggerImplementationMethodCallEventSourceEventTemplate.Template_LOGGER_METHOD_CALL_EVENTSOURCE_EVENT; output = output.Replace(LoggerImplementationMethodCallEventSourceEventTemplate.Variable_EVENTSOURCE_CLASS_NAME, eventSourceModel.ClassName); output = output.Replace(LoggerImplementationMethodCallEventSourceEventTemplate.Variable_LOGGER_METHOD_NAME, model.Name); var callArguments = new EventArgumentsListBuilder( RenderEventSourceEventMethodCallArgument, LoggerImplementationMethodCallEventSourceEventTemplate.Template_LOGGER_CALL_ARGUMENTS_DELIMITER); foreach (var argument in model.GetAllArguments()) { callArguments.Append(argument); } output = output.Replace(LoggerImplementationMethodCallEventSourceEventTemplate.Variable_LOGGER_METHOD_IMPLEMENTATION_CALL_ARGUMENTS, callArguments.ToString()); return(output); }
public void Render(Project project, ProjectItem <LoggerModel> model) { if (model.ItemType != ProjectItemType.LoggerImplementation) { LogError($"{model.Name} should be of ItemType {nameof(ProjectItemType.LoggerImplementation)} set but found {model.ItemType}"); return; } var loggerModel = model.Content; if (loggerModel == null) { LogError($"{model.Name} should have a content of type {typeof(EventSourceModel).Name} set but found {model.Content?.GetType().Name ?? "null"}"); return; } var eventSourceProjectItem = model.DependentUpon as ProjectItem <EventSourceModel>; var eventSourceModel = eventSourceProjectItem?.Content; if (eventSourceModel == null) { LogError($"{model.Name} should be DependentUpon a ProjectItem<EventSourceModel>, but found {model.DependentUpon?.GetType().Name ?? "null"}"); return; } var output = LoggerImplementationTemplate.Template_LOGGER_CLASS_DECLARATION; output = output.Replace(LoggerImplementationTemplate.Variable_LOGGER_SOURCE_FILE_NAME, loggerModel.SourceFileName); output = output.Replace(LoggerImplementationTemplate.Variable_NAMESPACE_DECLARATION, loggerModel.LoggerNamespace); output = output.Replace(LoggerImplementationTemplate.Variable_LOGGER_NAME, loggerModel.Name); output = output.Replace(LoggerImplementationTemplate.Variable_LOGGER_CLASS_NAME, loggerModel.ClassName); output = output.Replace(LoggerImplementationTemplate.Variable_EVENTSOURCE_NAMESPACE, eventSourceModel.Namespace); var memberDeclarations = new EventArgumentsListBuilder( RenderPrivateDeclaration, LoggerImplementationTemplate.Template_LOGGER_IMPLICIT_ARGUMENTS_MEMBER_DECLARATION_DELIMITER); var constructorMemberAssignments = new EventArgumentsListBuilder( RenderPrivateAssignment, LoggerImplementationTemplate.Variable_LOGGER_IMPLICIT_ARGUMENTS_MEMBER_ASSIGNMENT_DELIMITER); var constructorArguments = new EventArgumentsListBuilder( RenderMethodArgument, LoggerImplementationTemplate.Variable_LOGGER_IMPLICIT_ARGUMENTS_METHOD_CONSTRUCTOR_DELIMITER); foreach (var argument in loggerModel.ImplicitArguments) { memberDeclarations.Append(argument); constructorArguments.Append(argument); constructorMemberAssignments.Append(argument); } var usings = new StringBuilder(); var usingRenderers = new ILoggerImplementationUsingRenderer[] { }.Union(project.GetExtensions <ILoggerImplementationUsingRenderer>(eventSourceModel.Settings?.Modules ?? new string[0])).ToArray(); foreach (var renderer in usingRenderers) { PassAlongLoggers(renderer as IWithLogging); usings.Append(renderer.Render(project, model)); } var useReferencedHelpers = loggerModel.EventSource.Settings.UseReferencedHelpers ? "using FG.Diagnostics.AutoLogger.Model;\r\n" : ""; var memberRenderers = new ILoggerImplementationMembersRenderer[] { }.Union(project.GetExtensions <ILoggerImplementationMembersRenderer>(eventSourceModel.Settings?.Modules ?? new string[0])).ToArray(); foreach (var renderer in memberRenderers) { PassAlongLoggers(renderer as IWithLogging); memberDeclarations.Append(renderer.Render(project, model)); } var constructorRenderers = new ILoggerImplementationConstructorRenderer[] { }.Union(project.GetExtensions <ILoggerImplementationConstructorRenderer>(eventSourceModel.Settings?.Modules ?? new string[0])).ToArray(); foreach (var renderer in constructorRenderers) { PassAlongLoggers(renderer as IWithLogging); constructorMemberAssignments.Append(renderer.Render(project, model)); } var scopeWrappers = !loggerModel.EventSource.Settings.UseReferencedHelpers ? LoggerImplementationTemplate.Template_LOGGER_IMPLEMENTATION_SCOPE_WRAPPERS : ""; output = output.Replace(LoggerImplementationTemplate.Variable_LOGGER_IMPLICIT_USING_DECLARATION, usings.ToString()); output = output.Replace(LoggerImplementationTemplate.Variable_LOGGER_IMPLICIT_ARGUMENTS_MEMBER_DECLARATION, memberDeclarations.ToString()); output = output.Replace(LoggerImplementationTemplate.Variable_LOGGER_IMPLICIT_ARGUMENTS_MEMBER_ASSIGNMENT, constructorMemberAssignments.ToString()); output = output.Replace(LoggerImplementationTemplate.Variable_LOGGER_IMPLICIT_ARGUMENTS_CONSTRUCTOR_DECLARATION, constructorArguments.ToString()); output = output.Replace(LoggerImplementationTemplate.Variable_LOGGER_USING_AUTOLOGGER_MODEL, useReferencedHelpers); output = output.Replace(LoggerImplementationTemplate.Variable_LOGGER_IMPLEMENTATION_SCOPE_WRAPPERS, scopeWrappers); var logger = new StringBuilder(); var loggerEventRenderers = new ILoggerImplementationEventRenderer[] { new LoggerImplementationEventMethodRenderer(), }.Union(project.GetExtensions <ILoggerImplementationEventRenderer>(eventSourceModel.Settings?.Modules ?? new string[0])).ToArray(); foreach (var loggerEvent in loggerModel.Events) { foreach (var renderer in loggerEventRenderers) { PassAlongLoggers(renderer as IWithLogging); var eventRender = renderer.Render(project, model, loggerEvent); logger.AppendLine(eventRender); } } output = output.Replace(LoggerImplementationTemplate.Variable_LOGGER_IMPLEMENTATION, logger.ToString()); model.Output = output; }
public string Render(EventModel model, int index, EventSourcePrototype eventSource) { var outputEventMethod = Template.Template_EVENT_METHOD; outputEventMethod = outputEventMethod.Replace(Template.Variable_EVENT_NAME, model.Name); outputEventMethod = outputEventMethod.Replace(Template.Variable_EVENT_ID, index.ToString()); outputEventMethod = outputEventMethod.Replace(Template.Variable_EVENT_LEVEL, model.Level.ToString()); var outputNonEventMethod = Template.Template_NON_EVENT_METHOD; outputNonEventMethod = outputNonEventMethod.Replace(Template.Variable_EVENT_NAME, model.Name); var keywords = new ListBuilder("", " | ", ""); foreach (var keyword in model.Keywords ?? new KeywordModel[] { }) { keywords.Append($"Keywords.{keyword.Name}"); } var keywordsDeclaration = (keywords.Length > 0) ? $", Keywords = {keywords}" : ""; outputEventMethod = outputEventMethod.Replace(Template.Variable_EVENT_KEYWORDS_DECLARATION, keywordsDeclaration); var next = 0; var messageFormatBuilder = new ListBuilder($"{model.Name.GetHumanReadable()}", " ", " "); var eventMethodArgumentsDeclarationBuilder = new EventArgumentsListBuilder((arg) => arg.RenderMethodArgument(), Template.Template_EVENT_METHOD_ARGUMENT_DELIMITER); var nonEventMethodArgumentsDeclarationBuilder = new EventArgumentsListBuilder((arg) => arg.RenderMethodArgument(), Template.Template_NONEVENT_METHOD_ARGUMENT_DELIMITER); var callArgumentsBuilder = new EventArgumentsListBuilder((arg) => arg.RenderWriteEventMethodCallArgument(), Template.Template_EVENT_METHOD_CALL_ARGUMENT_DELIMITER); var assignmentArgumentsBuilder = new EventArgumentsListBuilder((arg) => (arg as EventSourceEventCustomArgument)?.Assignment.Replace(@"$this", arg.Name) ?? arg.Name, Template.Template_NON_EVENT_ASSIGNMENT_ARGUMENT_DELIMITER); var hasComplexArguments = false; var allArguments = new List <EventArgumentModel>(); var messageArgumentsStart = 0; var messageArgumentsCount = 0; if (model.ImplicitArguments != null && model.ImplicitArguments.Length > 0) { allArguments.AddRange(model.ImplicitArguments); messageArgumentsStart += model.ImplicitArguments.Length; } allArguments.AddRange(model.Arguments); var messageArgument = allArguments.FirstOrDefault(arg => model.Name.Equals("message", StringComparison.InvariantCultureIgnoreCase)); var messageArgumentIndex = messageArgument != null?allArguments.IndexOf(messageArgument) : -1; var flatIndex = 0; foreach (var argument in allArguments) { argument.SetCLRType(eventSource); var methodArgument = ""; if (argument is EventSourceEventCustomArgument) { methodArgument = argument.RenderMethodArgument(); if (flatIndex >= messageArgumentsStart) { messageFormatBuilder.Append($"{{{next}}}"); } var customArgument = argument as EventSourceEventCustomArgument; assignmentArgumentsBuilder.Append(customArgument); eventSource.AddKnownExtensions(customArgument, customArgument.CLRType); var originalCLRType = customArgument.CLRType; customArgument.CLRType = customArgument.AssignedCLRType ?? customArgument.CLRType; eventMethodArgumentsDeclarationBuilder.Append(customArgument); callArgumentsBuilder.Append(customArgument); customArgument.CLRType = originalCLRType; next += 1; } else if (!argument.IsComplexType()) { // Just render the argument as it is methodArgument = argument.RenderMethodArgument(); if (flatIndex >= messageArgumentsStart) { messageFormatBuilder.Append($"{{{next}}}"); } assignmentArgumentsBuilder.Append(argument); eventMethodArgumentsDeclarationBuilder.Append(argument); callArgumentsBuilder.Append(argument); next += 1; } else { // Split the argument according to a template hasComplexArguments = true; var template = eventSource.TypeTemplates.GeTypeTemplate(argument.Type); if (template != null) { methodArgument = argument.RenderMethodArgument(); foreach (var customArgument in template.Arguments) { if (flatIndex >= messageArgumentsStart) { messageFormatBuilder.Append($"{{{next}}}"); } customArgument.SetCLRType(eventSource); assignmentArgumentsBuilder.Append(customArgument); eventMethodArgumentsDeclarationBuilder.Append(customArgument); callArgumentsBuilder.Append(customArgument); next += 1; } } else { // Render it as ToString() methodArgument = argument.RenderMethodPureArgument(); if (flatIndex >= messageArgumentsStart) { messageFormatBuilder.Append($"{{{next}}}"); } assignmentArgumentsBuilder.Append($"{argument.Name}.ToString()"); eventMethodArgumentsDeclarationBuilder.Append(argument.RenderMethodArgument(useSimpleTypesOnly: true)); callArgumentsBuilder.Append(argument); next += 1; } } nonEventMethodArgumentsDeclarationBuilder.Append(methodArgument); flatIndex++; } outputNonEventMethod = outputNonEventMethod.Replace(Template.Variable_NON_EVENT_METHOD_ARGUMENTS, nonEventMethodArgumentsDeclarationBuilder.ToString()); outputNonEventMethod = outputNonEventMethod.Replace(Template.Variable_NON_EVENT_ASSIGNMENT_ARGUMENTS, assignmentArgumentsBuilder.ToString()); outputEventMethod = outputEventMethod.Replace(Template.Variable_EVENT_METHOD_ACCESS, hasComplexArguments ? "private" : "public"); outputEventMethod = outputEventMethod.Replace(Template.Variable_EVENT_METHOD_ARGUMENTS, eventMethodArgumentsDeclarationBuilder.ToString()); outputEventMethod = outputEventMethod.Replace(Template.Variable_WRITEEVENT_CALL_ARGUMENTS, callArgumentsBuilder.ToString()); var nonEventMethodDeclaration = hasComplexArguments ? outputNonEventMethod : ""; outputEventMethod = outputEventMethod.Replace(Template.Variable_NON_EVENT_METHOD_DECLARATION, nonEventMethodDeclaration); var formatter = $"{{{next - 1}}}"; if (model.MessageFormatter != null) { formatter = model.MessageFormatter; } else if (messageArgumentIndex >= 0) { formatter = $"{{{messageArgumentIndex}}}"; } else { formatter = messageFormatBuilder.ToString(); } outputEventMethod = outputEventMethod.Replace(Template.Variable_EVENT_MESSAGE_FORMATTER, formatter); //var formatter = messageFormatBuilder.ToString(); //output = output.Replace(Template_EVENT_METHOD_ARGUMENTS, MessageFormatter ?? "{7}"); return(outputEventMethod); }
protected string Render(EventModel model) { if (!model.HasComplexArguments) { return(""); } var outputNonEventMethod = EventSourceNonEventMethodTemplate.Template_NON_EVENT_METHOD; outputNonEventMethod = outputNonEventMethod.Replace(EventSourceNonEventMethodTemplate.Variable_EVENT_NAME, model.Name); var methodArgumentsDeclarationBuilder = new EventArgumentsListBuilder( RenderNonEventMethodArgument, EventSourceNonEventMethodTemplate.Template_NONEVENT_METHOD_ARGUMENT_DELIMITER); var assignmentArgumentsBuilder = new EventArgumentsListBuilder( RenderAssignment, EventSourceNonEventMethodTemplate.Template_NON_EVENT_ASSIGNMENT_ARGUMENT_DELIMITER); foreach (var argument in model.GetAllArguments()) { methodArgumentsDeclarationBuilder.Append(argument); } foreach (var argument in model.GetAllArgumentsExpanded()) { assignmentArgumentsBuilder.Append(argument); } outputNonEventMethod = outputNonEventMethod.Replace(EventSourceNonEventMethodTemplate.Variable_NON_EVENT_METHOD_ARGUMENTS, methodArgumentsDeclarationBuilder.ToString()); outputNonEventMethod = outputNonEventMethod.Replace(EventSourceNonEventMethodTemplate.Variable_NON_EVENT_ASSIGNMENT_ARGUMENTS, assignmentArgumentsBuilder.ToString()); return(outputNonEventMethod); }
private string RenderTrackException(EventModel model) { var exceptionName = GetExceptionArgumentName(model)?.Name; var propertyEventName = "Name"; var output = Template_LOGGER_METHOD_TRACKEXCEPTION_DECLARATION; output = output.Replace(Variable_LOGGER_METHOD_TRACKEXCEPTION_NAME, model.Name); output = output.Replace(Variable_LOGGER_METHOD_TRACKEXCEPTION_EXCEPTION_NAME, exceptionName); var arguments = new EventArgumentsListBuilder("", RenderDictionaryKeyValue, ",\r\n "); var eventArgumentModels = model.GetAllArgumentsExpanded(directArgumentAssignments: false).ToArray(); foreach (var argumentModel in eventArgumentModels) { if (argumentModel.Name == propertyEventName) { propertyEventName = null; } arguments.Append(argumentModel); } var nameIndex = 1; while (eventArgumentModels.Any(a => a.Name == propertyEventName)) { propertyEventName = $"Name{nameIndex}"; nameIndex++; } output = output.Replace(Variable_LOGGER_METHOD_TRACKEXCEPTION_EVENTNAME, propertyEventName); output = output.Replace(Variable_LOGGER_METHOD_TRACKEVENT_PROPERTIES_DECLARATION, arguments.ToString()); return(output); }
protected string Render(EventModel model) { var outputEventMethod = EventSourceEventMethodTemplate.Template_EVENT_METHOD; outputEventMethod = outputEventMethod.Replace(EventSourceEventMethodTemplate.Variable_EVENT_NAME, model.Name); outputEventMethod = outputEventMethod.Replace(EventSourceEventMethodTemplate.Variable_EVENT_ID, model.Id.ToString()); outputEventMethod = outputEventMethod.Replace(EventSourceEventMethodTemplate.Variable_EVENT_LEVEL, model.Level.ToString()); var keywords = new ListBuilder("", " | ", ""); foreach (var keyword in model.Keywords ?? new KeywordModel[] { }) { keywords.Append($"Keywords.{keyword.Name}"); } var keywordsDeclaration = (keywords.Length > 0) ? $", Keywords = {keywords}" : ""; outputEventMethod = outputEventMethod.Replace(EventSourceEventMethodTemplate.Variable_EVENT_KEYWORDS_DECLARATION, keywordsDeclaration); var opCode = (string)null; if (model.OpCode != null) { opCode = model.OpCode.ToString(); } var opCodeDeclaration = (opCode != null) ? $", Opcode = EventOpcode.{opCode}" : ""; outputEventMethod = outputEventMethod.Replace(EventSourceEventMethodTemplate.Variable_EVENT_OPCODE_DECLARATION, opCodeDeclaration); var eventMethodArgumentsDeclarationBuilder = new EventArgumentsListBuilder( RenderEventMethodArgument, EventSourceEventMethodTemplate.Template_EVENT_METHOD_ARGUMENT_DELIMITER); var writeEventMethodCallArgument = new EventArgumentsListBuilder( (arg) => RenderWriteEventMethodCallArgument(arg), EventSourceEventMethodTemplate.Template_EVENT_METHOD_CALL_ARGUMENT_DELIMITER); writeEventMethodCallArgument.Append($"{model.Name}EventId"); foreach (var argument in model.GetAllArgumentsExpanded()) { eventMethodArgumentsDeclarationBuilder.Append(argument); writeEventMethodCallArgument.Append(argument); } outputEventMethod = outputEventMethod.Replace(EventSourceEventMethodTemplate.Variable_EVENT_METHOD_ACCESS, model.HasComplexArguments ? "private" : "public"); outputEventMethod = outputEventMethod.Replace(EventSourceEventMethodTemplate.Variable_EVENT_METHOD_ARGUMENTS, eventMethodArgumentsDeclarationBuilder.ToString()); outputEventMethod = outputEventMethod.Replace(EventSourceEventMethodTemplate.Variable_WRITEEVENT_CALL_ARGUMENTS, writeEventMethodCallArgument.ToString()); outputEventMethod = outputEventMethod.Replace(EventSourceEventMethodTemplate.Variable_EVENT_MESSAGE_FORMATTER, model.MessageFormatter); return(outputEventMethod); }
private string RenderTrackEvent(EventModel model) { var output = Template_LOGGER_METHOD_TRACKEVENT_DECLARATION; output = output.Replace(Variable_LOGGER_METHOD_TRACKEVENT_NAME, model.Name); var arguments = new EventArgumentsListBuilder("", RenderDictionaryKeyValue, ",\r\n "); foreach (var argumentModel in model.GetAllArgumentsExpanded(directArgumentAssignments: false)) { arguments.Append(argumentModel); } output = output.Replace(Variable_LOGGER_METHOD_TRACKEVENT_PROPERTIES_DECLARATION, arguments.ToString()); return(output); }
private string RenderStartOperation(EventModel model) { var operationName = GetEventOperationName(model); var output = Template_LOGGER_METHOD_TRACKOPERATIONSTART_DECLARATION; var requestName = ""; var requestArgumentName = GetRequestNameArgument(model); if (requestArgumentName != null) { requestName = CreateDictionaryKeyValue(requestArgumentName).Value; } else { requestName = $"\"{operationName}\""; } output = output.Replace(Variable_LOGGER_METHOD_TRACKOPERATION_NAME, operationName); output = output.Replace(Variable_LOGGER_METHOD_TRACKOPERATION_REQUESTNAME, requestName); var arguments = new EventArgumentsListBuilder("", arg => RenderDictionaryKeyValueAdd(arg, operationName), "\r\n "); foreach (var argumentModel in model.GetAllArgumentsExpanded(directArgumentAssignments: false)) { arguments.Append(argumentModel); } output = output.Replace(Variable_LOGGER_METHOD_TRACKOPERATION_PROPERTIES_DECLARATION, arguments.ToString()); return(output); }
private string RenderStartScopedOperation(EventModel model) { var operationName = GetEventOperationName(model); var output = Template_LOGGER_METHOD_TRACKSCOPEDOPERATIONSTART_DECLARATION; var requestName = ""; var requestArgumentName = GetRequestNameArgument(model); if (requestArgumentName != null) { requestName = $"{CreateDictionaryKeyValue(requestArgumentName).Value} ?? \"{operationName}\""; } else { requestName = $"\"{operationName}\""; } var telemetryType = GetTelemetryType(model); output = output.Replace(Variable_LOGGER_METHOD_TRACKOPERATION_NAME, operationName); output = output.Replace(Variable_LOGGER_METHOD_TRACKOPERATION_REQUESTNAME, requestName); output = output.Replace(Variable_LOGGER_METHOD_TRACKOPERATION_TELEMETRYTYPE, telemetryType); output = output.Replace(Variable_LOGGER_METHOD_TRACKSCOPEDOPERATIONSTOP_METHOD_NAME, model.CorrelatesTo.Name); var arguments = new EventArgumentsListBuilder("", arg => RenderDictionaryKeyValueAdd(arg, operationName), "\r\n "); foreach (var argumentModel in model.GetAllArgumentsExpanded(directArgumentAssignments: false)) { arguments.Append(argumentModel); } output = output.Replace(Variable_LOGGER_METHOD_TRACKOPERATION_PROPERTIES_DECLARATION, arguments.ToString()); var stopOperationArguments = new EventArgumentsListBuilder("", arg => $"{arg.Name}", ","); foreach (var argumentModel in model.GetAllNonImplicitArguments()) { stopOperationArguments.Append(argumentModel); } output = output.Replace(Variable_LOGGER_METHOD_TRACKOPERATION_METHOD_ARGUMENTS_ASSIGNMENT, stopOperationArguments.ToString()); return(output); }
public string Render(Project project, ProjectItem <LoggerModel> loggerProjectItem, EventModel model) { if (loggerProjectItem.ItemType != ProjectItemType.LoggerImplementation) { LogError($"{loggerProjectItem.Name} should be of ItemType {nameof(ProjectItemType.LoggerImplementation)} set but found {loggerProjectItem.ItemType}"); return(""); } var loggerModel = loggerProjectItem.Content; if (loggerModel == null) { LogError($"{loggerProjectItem?.Name ?? nameof(loggerProjectItem)} should have content of type {typeof(LoggerModel).Name}, but found {loggerProjectItem?.GetType().Name ?? "null"}"); return(""); } var eventSourceModel = loggerModel.EventSource; if (eventSourceModel == null) { LogError($"{loggerProjectItem?.Name ?? nameof(loggerProjectItem)} should have content of type {typeof(LoggerModel).Name} with property EventSource set, but found {loggerModel.EventSource?.Name ?? "null"}"); return(""); } var eventName = model.Name; if ((model.ReturnType == "System.IDisposable") && (model.Name.StartsWith("Start"))) { eventName = model.Name.Substring("Start".Length); } /* * else if (model.CorrelatesTo?.ReturnType == "System.IDisposable" && (model.CorrelatesTo?.Name.StartsWith("Start") ?? false)) * { * return ""; * } */ var output = LoggerImplementationEventMethodTemplate.Template_LOGGER_METHOD; output = output.Replace(LoggerImplementationEventMethodTemplate.Variable_LOGGER_METHOD_NAME, eventName); output = output.Replace(LoggerImplementationEventMethodTemplate.Variable_EVENTSOURCE_CLASS_NAME, eventSourceModel.ClassName); output = output.Replace(LoggerImplementationEventMethodTemplate.Variable_LOGGER_METHOD_RETURNTYPE, model.ReturnType ?? "void"); var methodArguments = new EventArgumentsListBuilder( RenderMethodArgument, LoggerImplementationEventMethodTemplate.Template_LOGGER_IMPLICIT_ARGUMENTS_METHOD_DECLARATION_DELIMITER); foreach (var argument in model.GetAllNonImplicitArguments()) { methodArguments.Append(argument); } output = output.Replace(LoggerImplementationEventMethodTemplate.Variable_LOGGER_METHOD_ARGUMENTS, methodArguments.ToString()); var methodImplementation = new StringBuilder(); var renderers = new ILoggerImplementationMethodRenderer[] { new LoggerImplementationMethodCallEventSourceEventRenderer(), }.Union(project.GetExtensions <ILoggerImplementationMethodRenderer>()).ToArray(); foreach (var renderer in renderers) { methodImplementation.Append(renderer.Render(project, loggerProjectItem, model)); } output = output.Replace(LoggerImplementationEventMethodTemplate.Variable_LOGGER_METHOD_IMPLEMENTATION, methodImplementation.ToString()); return(output); }
private string RenderMethod(Project project, ProjectItem <LoggerModel> loggerProjectItem, EventSourceModel eventSourceModel, EventModel model) { var eventName = model.Name; var output = LoggerImplementationEventMethodTemplate.Template_LOGGER_METHOD; output = output.Replace(LoggerImplementationEventMethodTemplate.Variable_LOGGER_METHOD_NAME, eventName); output = output.Replace(LoggerImplementationEventMethodTemplate.Variable_EVENTSOURCE_CLASS_NAME, eventSourceModel.ClassName); output = output.Replace(LoggerImplementationEventMethodTemplate.Variable_LOGGER_METHOD_RETURNTYPE, model.ReturnType ?? "void"); var methodArguments = new EventArgumentsListBuilder( RenderMethodArgument, LoggerImplementationEventMethodTemplate.Template_LOGGER_IMPLICIT_ARGUMENTS_METHOD_DECLARATION_DELIMITER); foreach (var argument in model.GetAllNonImplicitArguments()) { methodArguments.Append(argument); } output = output.Replace(LoggerImplementationEventMethodTemplate.Variable_LOGGER_METHOD_ARGUMENTS, methodArguments.ToString()); var methodImplementation = new StringBuilder(); var renderers = new ILoggerImplementationMethodRenderer[] { new LoggerImplementationMethodCallEventSourceEventRenderer(), }.Union(project.GetExtensions <ILoggerImplementationMethodRenderer>(eventSourceModel.Settings?.Modules ?? new string[0])).ToArray(); foreach (var renderer in renderers) { PassAlongLoggers(renderer as IWithLogging); methodImplementation.Append(renderer.Render(project, loggerProjectItem, model)); } output = output.Replace(LoggerImplementationEventMethodTemplate.Variable_LOGGER_METHOD_IMPLEMENTATION, methodImplementation.ToString()); return(output); }